<!DOCTYPE html>
<html lang="en">
<head>


    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>async - Documentation</title>


    <link rel="icon" href="favicon.ico?v=2">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css">

    <link rel="stylesheet" href="styles/prettify-tomorrow.css">

    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,700">
    <link rel="stylesheet" href="styles/jsdoc-default.css">

    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/ionicons/2.0.1/css/ionicons.min.css">
</head>
<body>

<div class="navbar navbar-default navbar-fixed-top">
  <div class="navbar-header">
    <a class="navbar-brand" href="../">
        <img src="img/async-logo.svg" alt="Async.js">
    </a>
  </div>
  <ul class="nav navbar-nav">
    <li id="version-dropdown" class="dropdown">
      <a href="#" class="dropdown-toggle vertically-centered" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">v3.2.6 <span class="caret"></span>
      </a>
      <ul class="dropdown-menu">
        <li><a href="../v3/">v3.0.x</a></li>
        <li><a href="../v2/">v2.6.2</a></li>
        <li>
          <a href="https://github.com/caolan/async/blob/v1.5.2/README.md">v1.5.x</a>
        </li>
      </ul>
    </li>
    <li><a href="./index.html">Home</a></li>
    <li><a href="./docs.html">Docs</a></li>
    <li><a href="https://github.com/caolan/async/blob/master/CHANGELOG.md">Changelog</a></li>
    <li><a href="https://github.com/caolan/async"><i class="ion-social-github" aria-hidden="true"></i></a></li>
  </ul>
  <ul class="nav navbar-nav navbar-right">
    <form class="navbar-form navbar-left" role="search">
      <div class="form-group">
        <input type="text" class="form-control typeahead" id="doc-search" placeholder="Search" autofocus>
      </div>
    </form>
  </ul>
</div>


<input type="checkbox" id="nav-trigger" class="nav-trigger">
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<div id="main">
    <div id="main-container" data-spy="scroll" data-target="#toc" data-offset="50">
        
        <h1 class="page-title">async</h1>
        

        




<section>

<header>
    
        
            
        
    
</header>

<article>
    <div class="container-overview">
    
        
            <div class="description"><p>Async is a utility module which provides straight-forward, powerful functions
for working with asynchronous JavaScript. Although originally designed for
use with <a href="http://nodejs.org">Node.js</a> and installable via
<code>npm install --save async</code>, it can also be used directly in the browser.</p></div>
        

        
            





















<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="index.js.html">index.js</a>, <a href="index.js.html#line40">line 40</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><a href="global.html">AsyncFunction</a></li>
        </ul>
    </dd>
    

    
</dl>












        
    
    </div>

    

    

    

     

    

    

    

    

    
</article>

</section>




    
        
        <h1 class="page-title" id="collections">Collections</h1>
        

        




<section>

<header>
    
        
            
        
    
</header>

<article>
    <div class="container-overview">
    
        
            <div class="description"><p>A collection of <code>async</code> functions for manipulating collections, such as
arrays and objects.</p></div>
        

        
            





















<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="index.js.html">index.js</a>, <a href="index.js.html#line50">line 50</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
    
    </div>

    

    

    

     

    

    

    
        <h3 class="subsection-title">Methods</h3>

        
            

    

    <h4 class="name" id="concat"><span class="type-signature">(static) </span>concat<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import concat from &apos;async/concat&apos;;
</code></pre>
<p>Applies <code>iteratee</code> to each item in <code>coll</code>, concatenating the results. Returns
the concatenated list. The <code>iteratee</code>s are called in parallel, and the
results are concatenated as they return. The results array will be returned in
the original order of <code>coll</code> passed to the <code>iteratee</code> function.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>flatMap</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function to apply to each item in <code>coll</code>,
which should use an array as its result. Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished, or an error occurs. Results is an array
containing the concatenated results of the <code>iteratee</code> function. Invoked with
(err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A Promise, if no callback is passed</p>
</div>



    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt
// dir4 does not exist

let directoryList = [&apos;dir1&apos;,&apos;dir2&apos;,&apos;dir3&apos;];
let withMissingDirectoryList = [&apos;dir1&apos;,&apos;dir2&apos;,&apos;dir3&apos;, &apos;dir4&apos;];

// Using callbacks
async.concat(directoryList, fs.readdir, function(err, results) {
   if (err) {
       console.log(err);
   } else {
       console.log(results);
       // [ &apos;file1.txt&apos;, &apos;file2.txt&apos;, &apos;file3.txt&apos;, &apos;file4.txt&apos;, file5.txt ]
   }
});

// Error Handling
async.concat(withMissingDirectoryList, fs.readdir, function(err, results) {
   if (err) {
       console.log(err);
       // [ Error: ENOENT: no such file or directory ]
       // since dir4 does not exist
   } else {
       console.log(results);
   }
});

// Using Promises
async.concat(directoryList, fs.readdir)
.then(results =&gt; {
    console.log(results);
    // [ &apos;file1.txt&apos;, &apos;file2.txt&apos;, &apos;file3.txt&apos;, &apos;file4.txt&apos;, file5.txt ]
}).catch(err =&gt; {
     console.log(err);
});

// Error Handling
async.concat(withMissingDirectoryList, fs.readdir)
.then(results =&gt; {
    console.log(results);
}).catch(err =&gt; {
    console.log(err);
    // [ Error: ENOENT: no such file or directory ]
    // since dir4 does not exist
});

// Using async/await
async () =&gt; {
    try {
        let results = await async.concat(directoryList, fs.readdir);
        console.log(results);
        // [ &apos;file1.txt&apos;, &apos;file2.txt&apos;, &apos;file3.txt&apos;, &apos;file4.txt&apos;, file5.txt ]
    } catch (err) {
        console.log(err);
    }
}

// Error Handling
async () =&gt; {
    try {
        let results = await async.concat(withMissingDirectoryList, fs.readdir);
        console.log(results);
    } catch (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
        // since dir4 does not exist
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="concat.js.html">concat.js</a>, <a href="concat.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="concatLimit"><span class="type-signature">(static) </span>concatLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import concatLimit from &apos;async/concatLimit&apos;;
</code></pre>
<p>The same as <a href="#concat"><code>concat</code></a> but runs a maximum of <code>limit</code> async operations at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>flatMapLimit</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function to apply to each item in <code>coll</code>,
which should use an array as its result. Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished, or an error occurs. Results is an array
containing the concatenated results of the <code>iteratee</code> function. Invoked with
(err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A Promise, if no callback is passed</p>
</div>



    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="concatLimit.js.html">concatLimit.js</a>, <a href="concatLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#concat">async.concat</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="concatSeries"><span class="type-signature">(static) </span>concatSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import concatSeries from &apos;async/concatSeries&apos;;
</code></pre>
<p>The same as <a href="#concat"><code>concat</code></a> but runs only a single async operation at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>flatMapSeries</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function to apply to each item in <code>coll</code>.
The iteratee should complete with an array an array of results.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished, or an error occurs. Results is an array
containing the concatenated results of the <code>iteratee</code> function. Invoked with
(err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A Promise, if no callback is passed</p>
</div>



    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="concatSeries.js.html">concatSeries.js</a>, <a href="concatSeries.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#concat">async.concat</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="detect"><span class="type-signature">(static) </span>detect<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import detect from &apos;async/detect&apos;;
</code></pre>
<p>Returns the first value in <code>coll</code> that passes an async truth test. The
<code>iteratee</code> is applied in parallel, meaning the first iteratee to return
<code>true</code> will fire the detect <code>callback</code> with that result. That means the
result might not be the first item in the original <code>coll</code> (in terms of order)
that passes the test.
If order within the original <code>coll</code> is important, then look at
<a href="#detectSeries"><code>detectSeries</code></a>.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>find</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A truth test to apply to each item in <code>coll</code>.
The iteratee must complete with a boolean value as its result.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called as soon as any
iteratee returns <code>true</code>, or after all the <code>iteratee</code> functions have finished.
Result will be the first item in the array that passes the truth test
(iteratee) or the value <code>undefined</code> if none passed. Invoked with
(err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt

// asynchronous function that checks if a file exists
function fileExists(file, callback) {
   fs.access(file, fs.constants.F_OK, (err) =&gt; {
       callback(null, !err);
   });
}

async.detect([&apos;file3.txt&apos;,&apos;file2.txt&apos;,&apos;dir1/file1.txt&apos;], fileExists,
   function(err, result) {
       console.log(result);
       // dir1/file1.txt
       // result now equals the first file in the list that exists
   }
);

// Using Promises
async.detect([&apos;file3.txt&apos;,&apos;file2.txt&apos;,&apos;dir1/file1.txt&apos;], fileExists)
.then(result =&gt; {
    console.log(result);
    // dir1/file1.txt
    // result now equals the first file in the list that exists
}).catch(err =&gt; {
    console.log(err);
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.detect([&apos;file3.txt&apos;,&apos;file2.txt&apos;,&apos;dir1/file1.txt&apos;], fileExists);
        console.log(result);
        // dir1/file1.txt
        // result now equals the file in the list that exists
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="detect.js.html">detect.js</a>, <a href="detect.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="detectLimit"><span class="type-signature">(static) </span>detectLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import detectLimit from &apos;async/detectLimit&apos;;
</code></pre>
<p>The same as <a href="#detect"><code>detect</code></a> but runs a maximum of <code>limit</code> async operations at a
time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>findLimit</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A truth test to apply to each item in <code>coll</code>.
The iteratee must complete with a boolean value as its result.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called as soon as any
iteratee returns <code>true</code>, or after all the <code>iteratee</code> functions have finished.
Result will be the first item in the array that passes the truth test
(iteratee) or the value <code>undefined</code> if none passed. Invoked with
(err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="detectLimit.js.html">detectLimit.js</a>, <a href="detectLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#detect">async.detect</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="detectSeries"><span class="type-signature">(static) </span>detectSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import detectSeries from &apos;async/detectSeries&apos;;
</code></pre>
<p>The same as <a href="#detect"><code>detect</code></a> but runs only a single async operation at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>findSeries</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A truth test to apply to each item in <code>coll</code>.
The iteratee must complete with a boolean value as its result.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called as soon as any
iteratee returns <code>true</code>, or after all the <code>iteratee</code> functions have finished.
Result will be the first item in the array that passes the truth test
(iteratee) or the value <code>undefined</code> if none passed. Invoked with
(err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="detectSeries.js.html">detectSeries.js</a>, <a href="detectSeries.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#detect">async.detect</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="each"><span class="type-signature">(static) </span>each<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import each from &apos;async/each&apos;;
</code></pre>
<p>Applies the function <code>iteratee</code> to each item in <code>coll</code>, in parallel.
The <code>iteratee</code> is called with an item from the list, and a callback for when
it has finished. If the <code>iteratee</code> passes an error to its <code>callback</code>, the
main <code>callback</code> (for the <code>each</code> function) is immediately called with the
error.</p>
<p>Note, that since this function applies <code>iteratee</code> to each item in parallel,
there is no guarantee that the iteratee functions will complete in order.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>forEach</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to
each item in <code>coll</code>. Invoked with (item, callback).
The array index is not passed to the iteratee.
If you need the index, use <code>eachOf</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all
<code>iteratee</code> functions have finished, or an error occurs. Invoked with (err).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt
// dir4 does not exist

const fileList = [ &apos;dir1/file2.txt&apos;, &apos;dir2/file3.txt&apos;, &apos;dir/file5.txt&apos;];
const withMissingFileList = [&apos;dir1/file1.txt&apos;, &apos;dir4/file2.txt&apos;];

// asynchronous function that deletes a file
const deleteFile = function(file, callback) {
    fs.unlink(file, callback);
};

// Using callbacks
async.each(fileList, deleteFile, function(err) {
    if( err ) {
        console.log(err);
    } else {
        console.log(&apos;All files have been deleted successfully&apos;);
    }
});

// Error Handling
async.each(withMissingFileList, deleteFile, function(err){
    console.log(err);
    // [ Error: ENOENT: no such file or directory ]
    // since dir4/file2.txt does not exist
    // dir1/file1.txt could have been deleted
});

// Using Promises
async.each(fileList, deleteFile)
.then( () =&gt; {
    console.log(&apos;All files have been deleted successfully&apos;);
}).catch( err =&gt; {
    console.log(err);
});

// Error Handling
async.each(fileList, deleteFile)
.then( () =&gt; {
    console.log(&apos;All files have been deleted successfully&apos;);
}).catch( err =&gt; {
    console.log(err);
    // [ Error: ENOENT: no such file or directory ]
    // since dir4/file2.txt does not exist
    // dir1/file1.txt could have been deleted
});

// Using async/await
async () =&gt; {
    try {
        await async.each(files, deleteFile);
    }
    catch (err) {
        console.log(err);
    }
}

// Error Handling
async () =&gt; {
    try {
        await async.each(withMissingFileList, deleteFile);
    }
    catch (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
        // since dir4/file2.txt does not exist
        // dir1/file1.txt could have been deleted
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="each.js.html">each.js</a>, <a href="each.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="eachLimit"><span class="type-signature">(static) </span>eachLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import eachLimit from &apos;async/eachLimit&apos;;
</code></pre>
<p>The same as <a href="#each"><code>each</code></a> but runs a maximum of <code>limit</code> async operations at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>forEachLimit</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The array index is not passed to the iteratee.
If you need the index, use <code>eachOfLimit</code>.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all
<code>iteratee</code> functions have finished, or an error occurs. Invoked with (err).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="eachLimit.js.html">eachLimit.js</a>, <a href="eachLimit.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#each">async.each</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="eachOf"><span class="type-signature">(static) </span>eachOf<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import eachOf from &apos;async/eachOf&apos;;
</code></pre>
<p>Like <a href="#each"><code>each</code></a>, except that it passes the key (or index) as the second argument
to the iteratee.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>forEachOf</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function to apply to each
item in <code>coll</code>.
The <code>key</code> is the item&apos;s key, or index in the case of an array.
Invoked with (item, key, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all
<code>iteratee</code> functions have finished, or an error occurs. Invoked with (err).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dev.json is a file containing a valid json object config for dev environment
// dev.json is a file containing a valid json object config for test environment
// prod.json is a file containing a valid json object config for prod environment
// invalid.json is a file with a malformed json object

let configs = {}; //global variable
let validConfigFileMap = {dev: &apos;dev.json&apos;, test: &apos;test.json&apos;, prod: &apos;prod.json&apos;};
let invalidConfigFileMap = {dev: &apos;dev.json&apos;, test: &apos;test.json&apos;, invalid: &apos;invalid.json&apos;};

// asynchronous function that reads a json file and parses the contents as json object
function parseFile(file, key, callback) {
    fs.readFile(file, &quot;utf8&quot;, function(err, data) {
        if (err) return calback(err);
        try {
            configs[key] = JSON.parse(data);
        } catch (e) {
            return callback(e);
        }
        callback();
    });
}

// Using callbacks
async.forEachOf(validConfigFileMap, parseFile, function (err) {
    if (err) {
        console.error(err);
    } else {
        console.log(configs);
        // configs is now a map of JSON data, e.g.
        // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
    }
});

//Error handing
async.forEachOf(invalidConfigFileMap, parseFile, function (err) {
    if (err) {
        console.error(err);
        // JSON parse error exception
    } else {
        console.log(configs);
    }
});

// Using Promises
async.forEachOf(validConfigFileMap, parseFile)
.then( () =&gt; {
    console.log(configs);
    // configs is now a map of JSON data, e.g.
    // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
}).catch( err =&gt; {
    console.error(err);
});

//Error handing
async.forEachOf(invalidConfigFileMap, parseFile)
.then( () =&gt; {
    console.log(configs);
}).catch( err =&gt; {
    console.error(err);
    // JSON parse error exception
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.forEachOf(validConfigFileMap, parseFile);
        console.log(configs);
        // configs is now a map of JSON data, e.g.
        // { dev: //parsed dev.json, test: //parsed test.json, prod: //parsed prod.json}
    }
    catch (err) {
        console.log(err);
    }
}

//Error handing
async () =&gt; {
    try {
        let result = await async.forEachOf(invalidConfigFileMap, parseFile);
        console.log(configs);
    }
    catch (err) {
        console.log(err);
        // JSON parse error exception
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="eachOf.js.html">eachOf.js</a>, <a href="eachOf.js.html#line42">line 42</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#each">async.each</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="eachOfLimit"><span class="type-signature">(static) </span>eachOfLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import eachOfLimit from &apos;async/eachOfLimit&apos;;
</code></pre>
<p>The same as <a href="#eachOf"><code>eachOf</code></a> but runs a maximum of <code>limit</code> async operations at a
time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>forEachOfLimit</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each
item in <code>coll</code>. The <code>key</code> is the item&apos;s key, or index in the case of an
array.
Invoked with (item, key, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all
<code>iteratee</code> functions have finished, or an error occurs. Invoked with (err).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="eachOfLimit.js.html">eachOfLimit.js</a>, <a href="eachOfLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#eachOf">async.eachOf</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="eachOfSeries"><span class="type-signature">(static) </span>eachOfSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import eachOfSeries from &apos;async/eachOfSeries&apos;;
</code></pre>
<p>The same as <a href="#eachOf"><code>eachOf</code></a> but runs only a single async operation at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>forEachOfSeries</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
Invoked with (item, key, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. Invoked with (err).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="eachOfSeries.js.html">eachOfSeries.js</a>, <a href="eachOfSeries.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#eachOf">async.eachOf</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="eachSeries"><span class="type-signature">(static) </span>eachSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import eachSeries from &apos;async/eachSeries&apos;;
</code></pre>
<p>The same as <a href="#each"><code>each</code></a> but runs only a single async operation at a time.</p>
<p>Note, that unlike <a href="#each"><code>each</code></a>, this function applies iteratee to each item
in series and therefore the iteratee functions will complete in order.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>forEachSeries</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each
item in <code>coll</code>.
The array index is not passed to the iteratee.
If you need the index, use <code>eachOfSeries</code>.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all
<code>iteratee</code> functions have finished, or an error occurs. Invoked with (err).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="eachSeries.js.html">eachSeries.js</a>, <a href="eachSeries.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#each">async.each</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="every"><span class="type-signature">(static) </span>every<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import every from &apos;async/every&apos;;
</code></pre>
<p>Returns <code>true</code> if every element in <code>coll</code> satisfies an async test. If any
iteratee call returns <code>false</code>, the main <code>callback</code> is immediately called.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>all</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item
in the collection in parallel.
The iteratee must complete with a boolean result value.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Result will be either <code>true</code> or <code>false</code>
depending on the values of the async tests. Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt
// dir4 does not exist

const fileList = [&apos;dir1/file1.txt&apos;,&apos;dir2/file3.txt&apos;,&apos;dir3/file5.txt&apos;];
const withMissingFileList = [&apos;file1.txt&apos;,&apos;file2.txt&apos;,&apos;file4.txt&apos;];

// asynchronous function that checks if a file exists
function fileExists(file, callback) {
   fs.access(file, fs.constants.F_OK, (err) =&gt; {
       callback(null, !err);
   });
}

// Using callbacks
async.every(fileList, fileExists, function(err, result) {
    console.log(result);
    // true
    // result is true since every file exists
});

async.every(withMissingFileList, fileExists, function(err, result) {
    console.log(result);
    // false
    // result is false since NOT every file exists
});

// Using Promises
async.every(fileList, fileExists)
.then( result =&gt; {
    console.log(result);
    // true
    // result is true since every file exists
}).catch( err =&gt; {
    console.log(err);
});

async.every(withMissingFileList, fileExists)
.then( result =&gt; {
    console.log(result);
    // false
    // result is false since NOT every file exists
}).catch( err =&gt; {
    console.log(err);
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.every(fileList, fileExists);
        console.log(result);
        // true
        // result is true since every file exists
    }
    catch (err) {
        console.log(err);
    }
}

async () =&gt; {
    try {
        let result = await async.every(withMissingFileList, fileExists);
        console.log(result);
        // false
        // result is false since NOT every file exists
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="every.js.html">every.js</a>, <a href="every.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="everyLimit"><span class="type-signature">(static) </span>everyLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import everyLimit from &apos;async/everyLimit&apos;;
</code></pre>
<p>The same as <a href="#every"><code>every</code></a> but runs a maximum of <code>limit</code> async operations at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>allLimit</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item
in the collection in parallel.
The iteratee must complete with a boolean result value.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Result will be either <code>true</code> or <code>false</code>
depending on the values of the async tests. Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="everyLimit.js.html">everyLimit.js</a>, <a href="everyLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#every">async.every</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="everySeries"><span class="type-signature">(static) </span>everySeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import everySeries from &apos;async/everySeries&apos;;
</code></pre>
<p>The same as <a href="#every"><code>every</code></a> but runs only a single async operation at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>allSeries</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item
in the collection in series.
The iteratee must complete with a boolean result value.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Result will be either <code>true</code> or <code>false</code>
depending on the values of the async tests. Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="everySeries.js.html">everySeries.js</a>, <a href="everySeries.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#every">async.every</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="filter"><span class="type-signature">(static) </span>filter<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import filter from &apos;async/filter&apos;;
</code></pre>
<p>Returns a new array of all the values in <code>coll</code> which pass an async truth
test. This operation is performed in parallel, but the results array will be
in the same order as the original.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>select</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>A truth test to apply to each item in <code>coll</code>.
The <code>iteratee</code> is passed a <code>callback(err, truthValue)</code>, which must be called
with a boolean argument once it has completed. Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt

const files = [&apos;dir1/file1.txt&apos;,&apos;dir2/file3.txt&apos;,&apos;dir3/file6.txt&apos;];

// asynchronous function that checks if a file exists
function fileExists(file, callback) {
   fs.access(file, fs.constants.F_OK, (err) =&gt; {
       callback(null, !err);
   });
}

// Using callbacks
async.filter(files, fileExists, function(err, results) {
   if(err) {
       console.log(err);
   } else {
       console.log(results);
       // [ &apos;dir1/file1.txt&apos;, &apos;dir2/file3.txt&apos; ]
       // results is now an array of the existing files
   }
});

// Using Promises
async.filter(files, fileExists)
.then(results =&gt; {
    console.log(results);
    // [ &apos;dir1/file1.txt&apos;, &apos;dir2/file3.txt&apos; ]
    // results is now an array of the existing files
}).catch(err =&gt; {
    console.log(err);
});

// Using async/await
async () =&gt; {
    try {
        let results = await async.filter(files, fileExists);
        console.log(results);
        // [ &apos;dir1/file1.txt&apos;, &apos;dir2/file3.txt&apos; ]
        // results is now an array of the existing files
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="filter.js.html">filter.js</a>, <a href="filter.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="filterLimit"><span class="type-signature">(static) </span>filterLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import filterLimit from &apos;async/filterLimit&apos;;
</code></pre>
<p>The same as <a href="#filter"><code>filter</code></a> but runs a maximum of <code>limit</code> async operations at a
time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>selectLimit</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>A truth test to apply to each item in <code>coll</code>.
The <code>iteratee</code> is passed a <code>callback(err, truthValue)</code>, which must be called
with a boolean argument once it has completed. Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="filterLimit.js.html">filterLimit.js</a>, <a href="filterLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#filter">async.filter</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="filterSeries"><span class="type-signature">(static) </span>filterSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import filterSeries from &apos;async/filterSeries&apos;;
</code></pre>
<p>The same as <a href="#filter"><code>filter</code></a> but runs only a single async operation at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>selectSeries</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>A truth test to apply to each item in <code>coll</code>.
The <code>iteratee</code> is passed a <code>callback(err, truthValue)</code>, which must be called
with a boolean argument once it has completed. Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Invoked with (err, results)</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="filterSeries.js.html">filterSeries.js</a>, <a href="filterSeries.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#filter">async.filter</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="groupBy"><span class="type-signature">(static) </span>groupBy<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import groupBy from &apos;async/groupBy&apos;;
</code></pre>
<p>Returns a new object, where each value corresponds to an array of items, from
<code>coll</code>, that returned the corresponding key. That is, the keys of the object
correspond to the values passed to the <code>iteratee</code> callback.</p>
<p>Note: Since this function applies the <code>iteratee</code> to each item in parallel,
there is no guarantee that the <code>iteratee</code> functions will complete in order.
However, the values for each key in the <code>result</code> will be in the same order as
the original <code>coll</code>. For Objects, the values will roughly be in the order of
the original Objects&apos; keys (but this can vary across JavaScript engines).</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The iteratee should complete with a <code>key</code> to group the value under.
Invoked with (value, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. Result is an <code>Object</code> whoses
properties are arrays of values which returned the corresponding key.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt
// dir4 does not exist

const files = [&apos;dir1/file1.txt&apos;,&apos;dir2&apos;,&apos;dir4&apos;]

// asynchronous function that detects file type as none, file, or directory
function detectFile(file, callback) {
    fs.stat(file, function(err, stat) {
        if (err) {
            return callback(null, &apos;none&apos;);
        }
        callback(null, stat.isDirectory() ? &apos;directory&apos; : &apos;file&apos;);
    });
}

//Using callbacks
async.groupBy(files, detectFile, function(err, result) {
    if(err) {
        console.log(err);
    } else {
	       console.log(result);
        // {
        //     file: [ &apos;dir1/file1.txt&apos; ],
        //     none: [ &apos;dir4&apos; ],
        //     directory: [ &apos;dir2&apos;]
        // }
        // result is object containing the files grouped by type
    }
});

// Using Promises
async.groupBy(files, detectFile)
.then( result =&gt; {
    console.log(result);
    // {
    //     file: [ &apos;dir1/file1.txt&apos; ],
    //     none: [ &apos;dir4&apos; ],
    //     directory: [ &apos;dir2&apos;]
    // }
    // result is object containing the files grouped by type
}).catch( err =&gt; {
    console.log(err);
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.groupBy(files, detectFile);
        console.log(result);
        // {
        //     file: [ &apos;dir1/file1.txt&apos; ],
        //     none: [ &apos;dir4&apos; ],
        //     directory: [ &apos;dir2&apos;]
        // }
        // result is object containing the files grouped by type
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="groupBy.js.html">groupBy.js</a>, <a href="groupBy.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="groupByLimit"><span class="type-signature">(static) </span>groupByLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import groupByLimit from &apos;async/groupByLimit&apos;;
</code></pre>
<p>The same as <a href="#groupBy"><code>groupBy</code></a> but runs a maximum of <code>limit</code> async operations at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The iteratee should complete with a <code>key</code> to group the value under.
Invoked with (value, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. Result is an <code>Object</code> whoses
properties are arrays of values which returned the corresponding key.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="groupByLimit.js.html">groupByLimit.js</a>, <a href="groupByLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#groupBy">async.groupBy</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="groupBySeries"><span class="type-signature">(static) </span>groupBySeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import groupBySeries from &apos;async/groupBySeries&apos;;
</code></pre>
<p>The same as <a href="#groupBy"><code>groupBy</code></a> but runs only a single async operation at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The iteratee should complete with a <code>key</code> to group the value under.
Invoked with (value, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. Result is an <code>Object</code> whose
properties are arrays of values which returned the corresponding key.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="groupBySeries.js.html">groupBySeries.js</a>, <a href="groupBySeries.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#groupBy">async.groupBy</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="map"><span class="type-signature">(static) </span>map<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import map from &apos;async/map&apos;;
</code></pre>
<p>Produces a new collection of values by mapping each value in <code>coll</code> through
the <code>iteratee</code> function. The <code>iteratee</code> is called with an item from <code>coll</code>
and a callback for when it has finished processing. Each of these callbacks
takes 2 arguments: an <code>error</code>, and the transformed item from <code>coll</code>. If
<code>iteratee</code> passes an error to its callback, the main <code>callback</code> (for the
<code>map</code> function) is immediately called with the error.</p>
<p>Note, that since this function applies the <code>iteratee</code> to each item in
parallel, there is no guarantee that the <code>iteratee</code> functions will complete
in order. However, the results array will be in the same order as the
original <code>coll</code>.</p>
<p>If <code>map</code> is passed an Object, the results will be an Array.  The results
will roughly be in the order of the original Objects&apos; keys (but this can
vary across JavaScript engines).</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The iteratee should complete with the transformed item.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. Results is an Array of the
transformed items from the <code>coll</code>. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// file1.txt is a file that is 1000 bytes in size
// file2.txt is a file that is 2000 bytes in size
// file3.txt is a file that is 3000 bytes in size
// file4.txt does not exist

const fileList = [&apos;file1.txt&apos;,&apos;file2.txt&apos;,&apos;file3.txt&apos;];
const withMissingFileList = [&apos;file1.txt&apos;,&apos;file2.txt&apos;,&apos;file4.txt&apos;];

// asynchronous function that returns the file size in bytes
function getFileSizeInBytes(file, callback) {
    fs.stat(file, function(err, stat) {
        if (err) {
            return callback(err);
        }
        callback(null, stat.size);
    });
}

// Using callbacks
async.map(fileList, getFileSizeInBytes, function(err, results) {
    if (err) {
        console.log(err);
    } else {
        console.log(results);
        // results is now an array of the file size in bytes for each file, e.g.
        // [ 1000, 2000, 3000]
    }
});

// Error Handling
async.map(withMissingFileList, getFileSizeInBytes, function(err, results) {
    if (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
    } else {
        console.log(results);
    }
});

// Using Promises
async.map(fileList, getFileSizeInBytes)
.then( results =&gt; {
    console.log(results);
    // results is now an array of the file size in bytes for each file, e.g.
    // [ 1000, 2000, 3000]
}).catch( err =&gt; {
    console.log(err);
});

// Error Handling
async.map(withMissingFileList, getFileSizeInBytes)
.then( results =&gt; {
    console.log(results);
}).catch( err =&gt; {
    console.log(err);
    // [ Error: ENOENT: no such file or directory ]
});

// Using async/await
async () =&gt; {
    try {
        let results = await async.map(fileList, getFileSizeInBytes);
        console.log(results);
        // results is now an array of the file size in bytes for each file, e.g.
        // [ 1000, 2000, 3000]
    }
    catch (err) {
        console.log(err);
    }
}

// Error Handling
async () =&gt; {
    try {
        let results = await async.map(withMissingFileList, getFileSizeInBytes);
        console.log(results);
    }
    catch (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="map.js.html">map.js</a>, <a href="map.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="mapLimit"><span class="type-signature">(static) </span>mapLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import mapLimit from &apos;async/mapLimit&apos;;
</code></pre>
<p>The same as <a href="#map"><code>map</code></a> but runs a maximum of <code>limit</code> async operations at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The iteratee should complete with the transformed item.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. Results is an array of the
transformed items from the <code>coll</code>. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="mapLimit.js.html">mapLimit.js</a>, <a href="mapLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#map">async.map</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="mapSeries"><span class="type-signature">(static) </span>mapSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import mapSeries from &apos;async/mapSeries&apos;;
</code></pre>
<p>The same as <a href="#map"><code>map</code></a> but runs only a single async operation at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The iteratee should complete with the transformed item.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. Results is an array of the
transformed items from the <code>coll</code>. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="mapSeries.js.html">mapSeries.js</a>, <a href="mapSeries.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#map">async.map</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="mapValues"><span class="type-signature">(static) </span>mapValues<span class="signature">(obj, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import mapValues from &apos;async/mapValues&apos;;
</code></pre>
<p>A relative of <a href="#map"><code>map</code></a>, designed for use with objects.</p>
<p>Produces a new Object by mapping each value of <code>obj</code> through the <code>iteratee</code>
function. The <code>iteratee</code> is called each <code>value</code> and <code>key</code> from <code>obj</code> and a
callback for when it has finished processing. Each of these callbacks takes
two arguments: an <code>error</code>, and the transformed item from <code>obj</code>. If <code>iteratee</code>
passes an error to its callback, the main <code>callback</code> (for the <code>mapValues</code>
function) is immediately called with the error.</p>
<p>Note, the order of the keys in the result is not guaranteed.  The keys will
be roughly in the order they complete, (but this is very engine-specific)</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>obj</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function to apply to each value and key
in <code>coll</code>.
The iteratee should complete with the transformed value as its result.
Invoked with (value, key, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. <code>result</code> is a new object consisting
of each key from <code>obj</code>, with each transformed value on the right-hand side.
Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// file1.txt is a file that is 1000 bytes in size
// file2.txt is a file that is 2000 bytes in size
// file3.txt is a file that is 3000 bytes in size
// file4.txt does not exist

const fileMap = {
    f1: &apos;file1.txt&apos;,
    f2: &apos;file2.txt&apos;,
    f3: &apos;file3.txt&apos;
};

const withMissingFileMap = {
    f1: &apos;file1.txt&apos;,
    f2: &apos;file2.txt&apos;,
    f3: &apos;file4.txt&apos;
};

// asynchronous function that returns the file size in bytes
function getFileSizeInBytes(file, key, callback) {
    fs.stat(file, function(err, stat) {
        if (err) {
            return callback(err);
        }
        callback(null, stat.size);
    });
}

// Using callbacks
async.mapValues(fileMap, getFileSizeInBytes, function(err, result) {
    if (err) {
        console.log(err);
    } else {
        console.log(result);
        // result is now a map of file size in bytes for each file, e.g.
        // {
        //     f1: 1000,
        //     f2: 2000,
        //     f3: 3000
        // }
    }
});

// Error handling
async.mapValues(withMissingFileMap, getFileSizeInBytes, function(err, result) {
    if (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
    } else {
        console.log(result);
    }
});

// Using Promises
async.mapValues(fileMap, getFileSizeInBytes)
.then( result =&gt; {
    console.log(result);
    // result is now a map of file size in bytes for each file, e.g.
    // {
    //     f1: 1000,
    //     f2: 2000,
    //     f3: 3000
    // }
}).catch (err =&gt; {
    console.log(err);
});

// Error Handling
async.mapValues(withMissingFileMap, getFileSizeInBytes)
.then( result =&gt; {
    console.log(result);
}).catch (err =&gt; {
    console.log(err);
    // [ Error: ENOENT: no such file or directory ]
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.mapValues(fileMap, getFileSizeInBytes);
        console.log(result);
        // result is now a map of file size in bytes for each file, e.g.
        // {
        //     f1: 1000,
        //     f2: 2000,
        //     f3: 3000
        // }
    }
    catch (err) {
        console.log(err);
    }
}

// Error Handling
async () =&gt; {
    try {
        let result = await async.mapValues(withMissingFileMap, getFileSizeInBytes);
        console.log(result);
    }
    catch (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="mapValues.js.html">mapValues.js</a>, <a href="mapValues.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="mapValuesLimit"><span class="type-signature">(static) </span>mapValuesLimit<span class="signature">(obj, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import mapValuesLimit from &apos;async/mapValuesLimit&apos;;
</code></pre>
<p>The same as <a href="#mapValues"><code>mapValues</code></a> but runs a maximum of <code>limit</code> async operations at a
time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>obj</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function to apply to each value and key
in <code>coll</code>.
The iteratee should complete with the transformed value as its result.
Invoked with (value, key, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. <code>result</code> is a new object consisting
of each key from <code>obj</code>, with each transformed value on the right-hand side.
Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="mapValuesLimit.js.html">mapValuesLimit.js</a>, <a href="mapValuesLimit.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#mapValues">async.mapValues</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="mapValuesSeries"><span class="type-signature">(static) </span>mapValuesSeries<span class="signature">(obj, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import mapValuesSeries from &apos;async/mapValuesSeries&apos;;
</code></pre>
<p>The same as <a href="#mapValues"><code>mapValues</code></a> but runs only a single async operation at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>obj</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function to apply to each value and key
in <code>coll</code>.
The iteratee should complete with the transformed value as its result.
Invoked with (value, key, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called when all <code>iteratee</code>
functions have finished, or an error occurs. <code>result</code> is a new object consisting
of each key from <code>obj</code>, with each transformed value on the right-hand side.
Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="mapValuesSeries.js.html">mapValuesSeries.js</a>, <a href="mapValuesSeries.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#mapValues">async.mapValues</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="reduce"><span class="type-signature">(static) </span>reduce<span class="signature">(coll, memo, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import reduce from &apos;async/reduce&apos;;
</code></pre>
<p>Reduces <code>coll</code> into a single value using an async <code>iteratee</code> to return each
successive step. <code>memo</code> is the initial state of the reduction. This function
only operates in series.</p>
<p>For performance reasons, it may make sense to split a call to this function
into a parallel map, and then use the normal <code>Array.prototype.reduce</code> on the
results. This function is for situations where each step in the reduction
needs to be async; if you can get the data before reducing it, then it&apos;s
probably a good idea to do so.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>foldl</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>memo</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>The initial state of the reduction.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function applied to each item in the
array to produce the next step in the reduction.
The <code>iteratee</code> should complete with the next state of the reduction.
If the iteratee completes with an error, the reduction is stopped and the
main <code>callback</code> is immediately called with the error.
Invoked with (memo, item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Result is the reduced value. Invoked with
(err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// file1.txt is a file that is 1000 bytes in size
// file2.txt is a file that is 2000 bytes in size
// file3.txt is a file that is 3000 bytes in size
// file4.txt does not exist

const fileList = [&apos;file1.txt&apos;,&apos;file2.txt&apos;,&apos;file3.txt&apos;];
const withMissingFileList = [&apos;file1.txt&apos;,&apos;file2.txt&apos;,&apos;file3.txt&apos;, &apos;file4.txt&apos;];

// asynchronous function that computes the file size in bytes
// file size is added to the memoized value, then returned
function getFileSizeInBytes(memo, file, callback) {
    fs.stat(file, function(err, stat) {
        if (err) {
            return callback(err);
        }
        callback(null, memo + stat.size);
    });
}

// Using callbacks
async.reduce(fileList, 0, getFileSizeInBytes, function(err, result) {
    if (err) {
        console.log(err);
    } else {
        console.log(result);
        // 6000
        // which is the sum of the file sizes of the three files
    }
});

// Error Handling
async.reduce(withMissingFileList, 0, getFileSizeInBytes, function(err, result) {
    if (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
    } else {
        console.log(result);
    }
});

// Using Promises
async.reduce(fileList, 0, getFileSizeInBytes)
.then( result =&gt; {
    console.log(result);
    // 6000
    // which is the sum of the file sizes of the three files
}).catch( err =&gt; {
    console.log(err);
});

// Error Handling
async.reduce(withMissingFileList, 0, getFileSizeInBytes)
.then( result =&gt; {
    console.log(result);
}).catch( err =&gt; {
    console.log(err);
    // [ Error: ENOENT: no such file or directory ]
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.reduce(fileList, 0, getFileSizeInBytes);
        console.log(result);
        // 6000
        // which is the sum of the file sizes of the three files
    }
    catch (err) {
        console.log(err);
    }
}

// Error Handling
async () =&gt; {
    try {
        let result = await async.reduce(withMissingFileList, 0, getFileSizeInBytes);
        console.log(result);
    }
    catch (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="reduce.js.html">reduce.js</a>, <a href="reduce.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="reduceRight"><span class="type-signature">(static) </span>reduceRight<span class="signature">(array, memo, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import reduceRight from &apos;async/reduceRight&apos;;
</code></pre>
<p>Same as <a href="#reduce"><code>reduce</code></a>, only operates on <code>array</code> in reverse order.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>foldr</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>array</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>memo</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>The initial state of the reduction.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function applied to each item in the
array to produce the next step in the reduction.
The <code>iteratee</code> should complete with the next state of the reduction.
If the iteratee completes with an error, the reduction is stopped and the
main <code>callback</code> is immediately called with the error.
Invoked with (memo, item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Result is the reduced value. Invoked with
(err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="reduceRight.js.html">reduceRight.js</a>, <a href="reduceRight.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#reduce">async.reduce</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="reject"><span class="type-signature">(static) </span>reject<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import reject from &apos;async/reject&apos;;
</code></pre>
<p>The opposite of <a href="#filter"><code>filter</code></a>. Removes values that pass an <code>async</code> truth test.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item in
<code>coll</code>.
The should complete with a boolean value as its <code>result</code>.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt

const fileList = [&apos;dir1/file1.txt&apos;,&apos;dir2/file3.txt&apos;,&apos;dir3/file6.txt&apos;];

// asynchronous function that checks if a file exists
function fileExists(file, callback) {
   fs.access(file, fs.constants.F_OK, (err) =&gt; {
       callback(null, !err);
   });
}

// Using callbacks
async.reject(fileList, fileExists, function(err, results) {
   // [ &apos;dir3/file6.txt&apos; ]
   // results now equals an array of the non-existing files
});

// Using Promises
async.reject(fileList, fileExists)
.then( results =&gt; {
    console.log(results);
    // [ &apos;dir3/file6.txt&apos; ]
    // results now equals an array of the non-existing files
}).catch( err =&gt; {
    console.log(err);
});

// Using async/await
async () =&gt; {
    try {
        let results = await async.reject(fileList, fileExists);
        console.log(results);
        // [ &apos;dir3/file6.txt&apos; ]
        // results now equals an array of the non-existing files
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="reject.js.html">reject.js</a>, <a href="reject.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#filter">async.filter</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="rejectLimit"><span class="type-signature">(static) </span>rejectLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import rejectLimit from &apos;async/rejectLimit&apos;;
</code></pre>
<p>The same as <a href="#reject"><code>reject</code></a> but runs a maximum of <code>limit</code> async operations at a
time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item in
<code>coll</code>.
The should complete with a boolean value as its <code>result</code>.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rejectLimit.js.html">rejectLimit.js</a>, <a href="rejectLimit.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#reject">async.reject</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="rejectSeries"><span class="type-signature">(static) </span>rejectSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import rejectSeries from &apos;async/rejectSeries&apos;;
</code></pre>
<p>The same as <a href="#reject"><code>reject</code></a> but runs only a single async operation at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item in
<code>coll</code>.
The should complete with a boolean value as its <code>result</code>.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="rejectSeries.js.html">rejectSeries.js</a>, <a href="rejectSeries.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#reject">async.reject</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="some"><span class="type-signature">(static) </span>some<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import some from &apos;async/some&apos;;
</code></pre>
<p>Returns <code>true</code> if at least one element in the <code>coll</code> satisfies an async test.
If any iteratee call returns <code>true</code>, the main <code>callback</code> is immediately
called.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>any</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item
in the collections in parallel.
The iteratee should complete with a boolean <code>result</code> value.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called as soon as any
iteratee returns <code>true</code>, or after all the iteratee functions have finished.
Result will be either <code>true</code> or <code>false</code> depending on the values of the async
tests. Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// dir1 is a directory that contains file1.txt, file2.txt
// dir2 is a directory that contains file3.txt, file4.txt
// dir3 is a directory that contains file5.txt
// dir4 does not exist

// asynchronous function that checks if a file exists
function fileExists(file, callback) {
   fs.access(file, fs.constants.F_OK, (err) =&gt; {
       callback(null, !err);
   });
}

// Using callbacks
async.some([&apos;dir1/missing.txt&apos;,&apos;dir2/missing.txt&apos;,&apos;dir3/file5.txt&apos;], fileExists,
   function(err, result) {
       console.log(result);
       // true
       // result is true since some file in the list exists
   }
);

async.some([&apos;dir1/missing.txt&apos;,&apos;dir2/missing.txt&apos;,&apos;dir4/missing.txt&apos;], fileExists,
   function(err, result) {
       console.log(result);
       // false
       // result is false since none of the files exists
   }
);

// Using Promises
async.some([&apos;dir1/missing.txt&apos;,&apos;dir2/missing.txt&apos;,&apos;dir3/file5.txt&apos;], fileExists)
.then( result =&gt; {
    console.log(result);
    // true
    // result is true since some file in the list exists
}).catch( err =&gt; {
    console.log(err);
});

async.some([&apos;dir1/missing.txt&apos;,&apos;dir2/missing.txt&apos;,&apos;dir4/missing.txt&apos;], fileExists)
.then( result =&gt; {
    console.log(result);
    // false
    // result is false since none of the files exists
}).catch( err =&gt; {
    console.log(err);
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.some([&apos;dir1/missing.txt&apos;,&apos;dir2/missing.txt&apos;,&apos;dir3/file5.txt&apos;], fileExists);
        console.log(result);
        // true
        // result is true since some file in the list exists
    }
    catch (err) {
        console.log(err);
    }
}

async () =&gt; {
    try {
        let result = await async.some([&apos;dir1/missing.txt&apos;,&apos;dir2/missing.txt&apos;,&apos;dir4/missing.txt&apos;], fileExists);
        console.log(result);
        // false
        // result is false since none of the files exists
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="some.js.html">some.js</a>, <a href="some.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="someLimit"><span class="type-signature">(static) </span>someLimit<span class="signature">(coll, limit, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import someLimit from &apos;async/someLimit&apos;;
</code></pre>
<p>The same as <a href="#some"><code>some</code></a> but runs a maximum of <code>limit</code> async operations at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>anyLimit</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item
in the collections in parallel.
The iteratee should complete with a boolean <code>result</code> value.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called as soon as any
iteratee returns <code>true</code>, or after all the iteratee functions have finished.
Result will be either <code>true</code> or <code>false</code> depending on the values of the async
tests. Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="someLimit.js.html">someLimit.js</a>, <a href="someLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#some">async.some</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="someSeries"><span class="type-signature">(static) </span>someSeries<span class="signature">(coll, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import someSeries from &apos;async/someSeries&apos;;
</code></pre>
<p>The same as <a href="#some"><code>some</code></a> but runs only a single async operation at a time.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>anySeries</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async truth test to apply to each item
in the collections in series.
The iteratee should complete with a boolean <code>result</code> value.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called as soon as any
iteratee returns <code>true</code>, or after all the iteratee functions have finished.
Result will be either <code>true</code> or <code>false</code> depending on the values of the async
tests. Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="someSeries.js.html">someSeries.js</a>, <a href="someSeries.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#some">async.some</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="sortBy"><span class="type-signature">(static) </span>sortBy<span class="signature">(coll, iteratee, callback)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import sortBy from &apos;async/sortBy&apos;;
</code></pre>
<p>Sorts a list by the results of running each <code>coll</code> value through an async
<code>iteratee</code>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function to apply to each item in
<code>coll</code>.
The iteratee should complete with a value to use as the sort criteria as
its <code>result</code>.
Invoked with (item, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished, or an error occurs. Results is the items
from the original <code>coll</code> sorted by the values returned by the <code>iteratee</code>
calls. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// bigfile.txt is a file that is 251100 bytes in size
// mediumfile.txt is a file that is 11000 bytes in size
// smallfile.txt is a file that is 121 bytes in size

// asynchronous function that returns the file size in bytes
function getFileSizeInBytes(file, callback) {
    fs.stat(file, function(err, stat) {
        if (err) {
            return callback(err);
        }
        callback(null, stat.size);
    });
}

// Using callbacks
async.sortBy([&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;,&apos;bigfile.txt&apos;], getFileSizeInBytes,
    function(err, results) {
        if (err) {
            console.log(err);
        } else {
            console.log(results);
            // results is now the original array of files sorted by
            // file size (ascending by default), e.g.
            // [ &apos;smallfile.txt&apos;, &apos;mediumfile.txt&apos;, &apos;bigfile.txt&apos;]
        }
    }
);

// By modifying the callback parameter the
// sorting order can be influenced:

// ascending order
async.sortBy([&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;,&apos;bigfile.txt&apos;], function(file, callback) {
    getFileSizeInBytes(file, function(getFileSizeErr, fileSize) {
        if (getFileSizeErr) return callback(getFileSizeErr);
        callback(null, fileSize);
    });
}, function(err, results) {
        if (err) {
            console.log(err);
        } else {
            console.log(results);
            // results is now the original array of files sorted by
            // file size (ascending by default), e.g.
            // [ &apos;smallfile.txt&apos;, &apos;mediumfile.txt&apos;, &apos;bigfile.txt&apos;]
        }
    }
);

// descending order
async.sortBy([&apos;bigfile.txt&apos;,&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;], function(file, callback) {
    getFileSizeInBytes(file, function(getFileSizeErr, fileSize) {
        if (getFileSizeErr) {
            return callback(getFileSizeErr);
        }
        callback(null, fileSize * -1);
    });
}, function(err, results) {
        if (err) {
            console.log(err);
        } else {
            console.log(results);
            // results is now the original array of files sorted by
            // file size (ascending by default), e.g.
            // [ &apos;bigfile.txt&apos;, &apos;mediumfile.txt&apos;, &apos;smallfile.txt&apos;]
        }
    }
);

// Error handling
async.sortBy([&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;,&apos;missingfile.txt&apos;], getFileSizeInBytes,
    function(err, results) {
        if (err) {
            console.log(err);
            // [ Error: ENOENT: no such file or directory ]
        } else {
            console.log(results);
        }
    }
);

// Using Promises
async.sortBy([&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;,&apos;bigfile.txt&apos;], getFileSizeInBytes)
.then( results =&gt; {
    console.log(results);
    // results is now the original array of files sorted by
    // file size (ascending by default), e.g.
    // [ &apos;smallfile.txt&apos;, &apos;mediumfile.txt&apos;, &apos;bigfile.txt&apos;]
}).catch( err =&gt; {
    console.log(err);
});

// Error handling
async.sortBy([&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;,&apos;missingfile.txt&apos;], getFileSizeInBytes)
.then( results =&gt; {
    console.log(results);
}).catch( err =&gt; {
    console.log(err);
    // [ Error: ENOENT: no such file or directory ]
});

// Using async/await
(async () =&gt; {
    try {
        let results = await async.sortBy([&apos;bigfile.txt&apos;,&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;], getFileSizeInBytes);
        console.log(results);
        // results is now the original array of files sorted by
        // file size (ascending by default), e.g.
        // [ &apos;smallfile.txt&apos;, &apos;mediumfile.txt&apos;, &apos;bigfile.txt&apos;]
    }
    catch (err) {
        console.log(err);
    }
})();

// Error handling
async () =&gt; {
    try {
        let results = await async.sortBy([&apos;missingfile.txt&apos;,&apos;mediumfile.txt&apos;,&apos;smallfile.txt&apos;], getFileSizeInBytes);
        console.log(results);
    }
    catch (err) {
        console.log(err);
        // [ Error: ENOENT: no such file or directory ]
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="sortBy.js.html">sortBy.js</a>, <a href="sortBy.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="transform"><span class="type-signature">(static) </span>transform<span class="signature">(coll, accumulator<span class="signature-attributes">opt</span>, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import transform from &apos;async/transform&apos;;
</code></pre>
<p>A relative of <code>reduce</code>.  Takes an Object or Array, and iterates over each
element in parallel, each step potentially mutating an <code>accumulator</code> value.
The type of the accumulator defaults to the type of collection passed in.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>coll</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection to iterate over.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>accumulator</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>The initial state of the transform.  If omitted,
it will default to an empty Object or Array, depending on the type of <code>coll</code></p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function applied to each item in the
collection that potentially modifies the accumulator.
Invoked with (accumulator, item, key, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after all the
<code>iteratee</code> functions have finished. Result is the transformed accumulator.
Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Examples</h5>
    
    <pre class="prettyprint"><code>// file1.txt is a file that is 1000 bytes in size
// file2.txt is a file that is 2000 bytes in size
// file3.txt is a file that is 3000 bytes in size

// helper function that returns human-readable size format from bytes
function formatBytes(bytes, decimals = 2) {
  // implementation not included for brevity
  return humanReadbleFilesize;
}

const fileList = [&apos;file1.txt&apos;,&apos;file2.txt&apos;,&apos;file3.txt&apos;];

// asynchronous function that returns the file size, transformed to human-readable format
// e.g. 1024 bytes = 1KB, 1234 bytes = 1.21 KB, 1048576 bytes = 1MB, etc.
function transformFileSize(acc, value, key, callback) {
    fs.stat(value, function(err, stat) {
        if (err) {
            return callback(err);
        }
        acc[key] = formatBytes(stat.size);
        callback(null);
    });
}

// Using callbacks
async.transform(fileList, transformFileSize, function(err, result) {
    if(err) {
        console.log(err);
    } else {
        console.log(result);
        // [ &apos;1000 Bytes&apos;, &apos;1.95 KB&apos;, &apos;2.93 KB&apos; ]
    }
});

// Using Promises
async.transform(fileList, transformFileSize)
.then(result =&gt; {
    console.log(result);
    // [ &apos;1000 Bytes&apos;, &apos;1.95 KB&apos;, &apos;2.93 KB&apos; ]
}).catch(err =&gt; {
    console.log(err);
});

// Using async/await
(async () =&gt; {
    try {
        let result = await async.transform(fileList, transformFileSize);
        console.log(result);
        // [ &apos;1000 Bytes&apos;, &apos;1.95 KB&apos;, &apos;2.93 KB&apos; ]
    }
    catch (err) {
        console.log(err);
    }
})();</code></pre>

    <pre class="prettyprint"><code>// file1.txt is a file that is 1000 bytes in size
// file2.txt is a file that is 2000 bytes in size
// file3.txt is a file that is 3000 bytes in size

// helper function that returns human-readable size format from bytes
function formatBytes(bytes, decimals = 2) {
  // implementation not included for brevity
  return humanReadbleFilesize;
}

const fileMap = { f1: &apos;file1.txt&apos;, f2: &apos;file2.txt&apos;, f3: &apos;file3.txt&apos; };

// asynchronous function that returns the file size, transformed to human-readable format
// e.g. 1024 bytes = 1KB, 1234 bytes = 1.21 KB, 1048576 bytes = 1MB, etc.
function transformFileSize(acc, value, key, callback) {
    fs.stat(value, function(err, stat) {
        if (err) {
            return callback(err);
        }
        acc[key] = formatBytes(stat.size);
        callback(null);
    });
}

// Using callbacks
async.transform(fileMap, transformFileSize, function(err, result) {
    if(err) {
        console.log(err);
    } else {
        console.log(result);
        // { f1: &apos;1000 Bytes&apos;, f2: &apos;1.95 KB&apos;, f3: &apos;2.93 KB&apos; }
    }
});

// Using Promises
async.transform(fileMap, transformFileSize)
.then(result =&gt; {
    console.log(result);
    // { f1: &apos;1000 Bytes&apos;, f2: &apos;1.95 KB&apos;, f3: &apos;2.93 KB&apos; }
}).catch(err =&gt; {
    console.log(err);
});

// Using async/await
async () =&gt; {
    try {
        let result = await async.transform(fileMap, transformFileSize);
        console.log(result);
        // { f1: &apos;1000 Bytes&apos;, f2: &apos;1.95 KB&apos;, f3: &apos;2.93 KB&apos; }
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="transform.js.html">transform.js</a>, <a href="transform.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
    

    

    
</article>

</section>




    
        
        <h1 class="page-title" id="controlflow">Control Flow</h1>
        

        




<section>

<header>
    
        
            
        
    
</header>

<article>
    <div class="container-overview">
    
        
            <div class="description"><p>A collection of <code>async</code> functions for controlling the flow through a script.</p></div>
        

        
            





















<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="index.js.html">index.js</a>, <a href="index.js.html#line56">line 56</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
    
    </div>

    

    

    

     

    

    

    
        <h3 class="subsection-title">Methods</h3>

        
            

    

    <h4 class="name" id="applyEach"><span class="type-signature">(static) </span>applyEach<span class="signature">(fns, &#x2026;args<span class="signature-attributes">opt</span>, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import applyEach from &apos;async/applyEach&apos;;
</code></pre>
<p>Applies the provided arguments to each function in the array, calling
<code>callback</code> after all functions have completed. If you only provide the first
argument, <code>fns</code>, then it will return a function which lets you pass in the
arguments as if it were a single function call. If more arguments are
provided, <code>callback</code> is required while <code>args</code> is still optional. The results
for each of the applied async functions are passed to the final callback
as an array.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fns</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection of <a href="global.html">AsyncFunction</a>s
to all call with the same arguments</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>args</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>any number of separate arguments to pass to the
function.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>the final argument should be the callback,
called when all functions have completed processing.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <ul>
<li>Returns a function that takes no args other than
an optional callback, that is the result of applying the <code>args</code> to each
of the functions.</li>
</ul>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>const appliedFn = async.applyEach([enableSearch, updateSchema], &apos;bucket&apos;)

appliedFn((err, results) =&gt; {
    // results[0] is the results for `enableSearch`
    // results[1] is the results for `updateSchema`
});

// partial application example:
async.each(
    buckets,
    async (bucket) =&gt; async.applyEach([enableSearch, updateSchema], bucket)(),
    callback
);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="applyEach.js.html">applyEach.js</a>, <a href="applyEach.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="applyEachSeries"><span class="type-signature">(static) </span>applyEachSeries<span class="signature">(fns, &#x2026;args<span class="signature-attributes">opt</span>, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import applyEachSeries from &apos;async/applyEachSeries&apos;;
</code></pre>
<p>The same as <a href="#applyEach"><code>applyEach</code></a> but runs only a single async operation at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fns</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection of <a href="global.html">AsyncFunction</a>s to all
call with the same arguments</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>args</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>any number of separate arguments to pass to the
function.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>the final argument should be the callback,
called when all functions have completed processing.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <ul>
<li>A function, that when called, is the result of
appling the <code>args</code> to the list of functions.  It takes no args, other than
a callback.</li>
</ul>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="applyEachSeries.js.html">applyEachSeries.js</a>, <a href="applyEachSeries.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#applyEach">async.applyEach</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="auto"><span class="type-signature">(static) </span>auto<span class="signature">(tasks, concurrency<span class="signature-attributes">opt</span>, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import auto from &apos;async/auto&apos;;
</code></pre>
<p>Determines the best order for running the <a href="global.html">AsyncFunction</a>s in <code>tasks</code>, based on
their requirements. Each function can optionally depend on other functions
being completed first, and each function is run as soon as its requirements
are satisfied.</p>
<p>If any of the <a href="global.html">AsyncFunction</a>s pass an error to their callback, the <code>auto</code> sequence
will stop. Further tasks will not execute (so any other functions depending
on it will not run), and the main <code>callback</code> is immediately called with the
error.</p>
<p><a href="global.html">AsyncFunction</a>s also receive an object containing the results of functions which
have completed so far as the first argument, if they have dependencies. If a
task function has no dependencies, it will only be passed a callback.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            

            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>An object. Each of its properties is either a
function or an array of requirements, with the <a href="global.html">AsyncFunction</a> itself the last item
in the array. The object&apos;s key of a property serves as the name of the task
defined by that property, i.e. can be used when specifying requirements for
other tasks. The function receives one or two arguments:</p>
<ul>
<li>a <code>results</code> object, containing the results of the previously executed
functions, only passed if the task has any dependencies,</li>
<li>a <code>callback(err, result)</code> function, which must be called when finished,
passing an <code>error</code> (which can be <code>null</code>) and the result of the function&apos;s
execution.</li>
</ul></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>concurrency</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                    Infinity
                
                </td>
            

            <td class="description last"><p>An optional <code>integer</code> for
determining the maximum number of tasks that can be run in parallel. By
default, as many as possible.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>An optional callback which is called when all
the tasks have been completed. It receives the <code>err</code> argument if any <code>tasks</code>
pass an error to their callback. Results are always returned; however, if an
error occurs, no further <code>tasks</code> will be performed, and the results object
will only contain partial results. Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is not passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>//Using Callbacks
async.auto({
    get_data: function(callback) {
        // async code to get some data
        callback(null, &apos;data&apos;, &apos;converted to array&apos;);
    },
    make_folder: function(callback) {
        // async code to create a directory to store a file in
        // this is run at the same time as getting the data
        callback(null, &apos;folder&apos;);
    },
    write_file: [&apos;get_data&apos;, &apos;make_folder&apos;, function(results, callback) {
        // once there is some data and the directory exists,
        // write the data to a file in the directory
        callback(null, &apos;filename&apos;);
    }],
    email_link: [&apos;write_file&apos;, function(results, callback) {
        // once the file is written let&apos;s email a link to it...
        callback(null, {&apos;file&apos;:results.write_file, &apos;email&apos;:&apos;user@example.com&apos;});
    }]
}, function(err, results) {
    if (err) {
        console.log(&apos;err = &apos;, err);
    }
    console.log(&apos;results = &apos;, results);
    // results = {
    //     get_data: [&apos;data&apos;, &apos;converted to array&apos;]
    //     make_folder; &apos;folder&apos;,
    //     write_file: &apos;filename&apos;
    //     email_link: { file: &apos;filename&apos;, email: &apos;user@example.com&apos; }
    // }
});

//Using Promises
async.auto({
    get_data: function(callback) {
        console.log(&apos;in get_data&apos;);
        // async code to get some data
        callback(null, &apos;data&apos;, &apos;converted to array&apos;);
    },
    make_folder: function(callback) {
        console.log(&apos;in make_folder&apos;);
        // async code to create a directory to store a file in
        // this is run at the same time as getting the data
        callback(null, &apos;folder&apos;);
    },
    write_file: [&apos;get_data&apos;, &apos;make_folder&apos;, function(results, callback) {
        // once there is some data and the directory exists,
        // write the data to a file in the directory
        callback(null, &apos;filename&apos;);
    }],
    email_link: [&apos;write_file&apos;, function(results, callback) {
        // once the file is written let&apos;s email a link to it...
        callback(null, {&apos;file&apos;:results.write_file, &apos;email&apos;:&apos;user@example.com&apos;});
    }]
}).then(results =&gt; {
    console.log(&apos;results = &apos;, results);
    // results = {
    //     get_data: [&apos;data&apos;, &apos;converted to array&apos;]
    //     make_folder; &apos;folder&apos;,
    //     write_file: &apos;filename&apos;
    //     email_link: { file: &apos;filename&apos;, email: &apos;user@example.com&apos; }
    // }
}).catch(err =&gt; {
    console.log(&apos;err = &apos;, err);
});

//Using async/await
async () =&gt; {
    try {
        let results = await async.auto({
            get_data: function(callback) {
                // async code to get some data
                callback(null, &apos;data&apos;, &apos;converted to array&apos;);
            },
            make_folder: function(callback) {
                // async code to create a directory to store a file in
                // this is run at the same time as getting the data
                callback(null, &apos;folder&apos;);
            },
            write_file: [&apos;get_data&apos;, &apos;make_folder&apos;, function(results, callback) {
                // once there is some data and the directory exists,
                // write the data to a file in the directory
                callback(null, &apos;filename&apos;);
            }],
            email_link: [&apos;write_file&apos;, function(results, callback) {
                // once the file is written let&apos;s email a link to it...
                callback(null, {&apos;file&apos;:results.write_file, &apos;email&apos;:&apos;user@example.com&apos;});
            }]
        });
        console.log(&apos;results = &apos;, results);
        // results = {
        //     get_data: [&apos;data&apos;, &apos;converted to array&apos;]
        //     make_folder; &apos;folder&apos;,
        //     write_file: &apos;filename&apos;
        //     email_link: { file: &apos;filename&apos;, email: &apos;user@example.com&apos; }
        // }
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="auto.js.html">auto.js</a>, <a href="auto.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="autoInject"><span class="type-signature">(static) </span>autoInject<span class="signature">(tasks, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import autoInject from &apos;async/autoInject&apos;;
</code></pre>
<p>A dependency-injected version of the <a href="#auto">async.auto</a> function. Dependent
tasks are specified as parameters to the function, after the usual callback
parameter, with the parameter names matching the names of the tasks it
depends on. This can provide even more readable task graphs which can be
easier to maintain.</p>
<p>If a final callback is specified, the task results are similarly injected,
specified as named parameters after the initial error parameter.</p>
<p>The autoInject function is purely syntactic sugar and its semantics are
otherwise equivalent to <a href="#auto">async.auto</a>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>An object, each of whose properties is an <a href="global.html">AsyncFunction</a> of
the form &apos;func([dependencies...], callback). The object&apos;s key of a property
serves as the name of the task defined by that property, i.e. can be used
when specifying requirements for other tasks.</p>
<ul>
<li>The <code>callback</code> parameter is a <code>callback(err, result)</code> which must be called
when finished, passing an <code>error</code> (which can be <code>null</code>) and the result of
the function&apos;s execution. The remaining parameters name other tasks on
which the task is dependent, and the results from those tasks are the
arguments of those parameters.</li>
</ul></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>An optional callback which is called when all
the tasks have been completed. It receives the <code>err</code> argument if any <code>tasks</code>
pass an error to their callback, and a <code>results</code> object with any completed
task results, similar to <code>auto</code>.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>//  The example from `auto` can be rewritten as follows:
async.autoInject({
    get_data: function(callback) {
        // async code to get some data
        callback(null, &apos;data&apos;, &apos;converted to array&apos;);
    },
    make_folder: function(callback) {
        // async code to create a directory to store a file in
        // this is run at the same time as getting the data
        callback(null, &apos;folder&apos;);
    },
    write_file: function(get_data, make_folder, callback) {
        // once there is some data and the directory exists,
        // write the data to a file in the directory
        callback(null, &apos;filename&apos;);
    },
    email_link: function(write_file, callback) {
        // once the file is written let&apos;s email a link to it...
        // write_file contains the filename returned by write_file.
        callback(null, {&apos;file&apos;:write_file, &apos;email&apos;:&apos;user@example.com&apos;});
    }
}, function(err, results) {
    console.log(&apos;err = &apos;, err);
    console.log(&apos;email_link = &apos;, results.email_link);
});

// If you are using a JS minifier that mangles parameter names, `autoInject`
// will not work with plain functions, since the parameter names will be
// collapsed to a single letter identifier.  To work around this, you can
// explicitly specify the names of the parameters your task function needs
// in an array, similar to Angular.js dependency injection.

// This still has an advantage over plain `auto`, since the results a task
// depends on are still spread into arguments.
async.autoInject({
    //...
    write_file: [&apos;get_data&apos;, &apos;make_folder&apos;, function(get_data, make_folder, callback) {
        callback(null, &apos;filename&apos;);
    }],
    email_link: [&apos;write_file&apos;, function(write_file, callback) {
        callback(null, {&apos;file&apos;:write_file, &apos;email&apos;:&apos;user@example.com&apos;});
    }]
    //...
}, function(err, results) {
    console.log(&apos;err = &apos;, err);
    console.log(&apos;email_link = &apos;, results.email_link);
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="autoInject.js.html">autoInject.js</a>, <a href="autoInject.js.html#line51">line 51</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#auto">async.auto</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="cargo"><span class="type-signature">(static) </span>cargo<span class="signature">(worker, payload<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {<a href="#QueueObject">QueueObject</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import cargo from &apos;async/cargo&apos;;
</code></pre>
<p>Creates a <code>cargo</code> object with the specified payload. Tasks added to the
cargo will be processed altogether (up to the <code>payload</code> limit). If the
<code>worker</code> is in progress, the task is queued until it becomes available. Once
the <code>worker</code> has completed some tasks, each callback of those tasks is
called. Check out <a href="https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966">these</a> <a href="https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966">animations</a>
for how <code>cargo</code> and <code>queue</code> work.</p>
<p>While <a href="#queue"><code>queue</code></a> passes only one task to one of a group of workers
at a time, cargo passes an array of tasks to a single worker, repeating
when the worker is finished.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>worker</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>An asynchronous function for processing an array
of queued tasks. Invoked with <code>(tasks, callback)</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>payload</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                    Infinity
                
                </td>
            

            <td class="description last"><p>An optional <code>integer</code> for determining
how many tasks should be processed per round; if omitted, the default is
unlimited.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A cargo object to manage the tasks. Callbacks can
attached as certain properties to listen for specific events during the
lifecycle of the cargo and inner queue.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="#QueueObject">QueueObject</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// create a cargo object with payload 2
var cargo = async.cargo(function(tasks, callback) {
    for (var i=0; i&lt;tasks.length; i++) {
        console.log(&apos;hello &apos; + tasks[i].name);
    }
    callback();
}, 2);

// add some items
cargo.push({name: &apos;foo&apos;}, function(err) {
    console.log(&apos;finished processing foo&apos;);
});
cargo.push({name: &apos;bar&apos;}, function(err) {
    console.log(&apos;finished processing bar&apos;);
});
await cargo.push({name: &apos;baz&apos;});
console.log(&apos;finished processing baz&apos;);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="cargo.js.html">cargo.js</a>, <a href="cargo.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#queue">async.queue</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="cargoQueue"><span class="type-signature">(static) </span>cargoQueue<span class="signature">(worker, concurrency<span class="signature-attributes">opt</span>, payload<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {<a href="#QueueObject">QueueObject</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import cargoQueue from &apos;async/cargoQueue&apos;;
</code></pre>
<p>Creates a <code>cargoQueue</code> object with the specified payload. Tasks added to the
cargoQueue will be processed together (up to the <code>payload</code> limit) in <code>concurrency</code> parallel workers.
If the all <code>workers</code> are in progress, the task is queued until one becomes available. Once
a <code>worker</code> has completed some tasks, each callback of those tasks is
called. Check out <a href="https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966">these</a> <a href="https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966">animations</a>
for how <code>cargo</code> and <code>queue</code> work.</p>
<p>While <a href="#queue"><code>queue</code></a> passes only one task to one of a group of workers
at a time, and <a href="#cargo"><code>cargo</code></a> passes an array of tasks to a single worker,
the cargoQueue passes an array of tasks to multiple parallel workers.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>worker</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>An asynchronous function for processing an array
of queued tasks. Invoked with <code>(tasks, callback)</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>concurrency</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                    1
                
                </td>
            

            <td class="description last"><p>An <code>integer</code> for determining how many
<code>worker</code> functions should be run in parallel.  If omitted, the concurrency
defaults to <code>1</code>.  If the concurrency is <code>0</code>, an error is thrown.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>payload</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                    Infinity
                
                </td>
            

            <td class="description last"><p>An optional <code>integer</code> for determining
how many tasks should be processed per round; if omitted, the default is
unlimited.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A cargoQueue object to manage the tasks. Callbacks can
attached as certain properties to listen for specific events during the
lifecycle of the cargoQueue and inner queue.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="#QueueObject">QueueObject</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// create a cargoQueue object with payload 2 and concurrency 2
var cargoQueue = async.cargoQueue(function(tasks, callback) {
    for (var i=0; i&lt;tasks.length; i++) {
        console.log(&apos;hello &apos; + tasks[i].name);
    }
    callback();
}, 2, 2);

// add some items
cargoQueue.push({name: &apos;foo&apos;}, function(err) {
    console.log(&apos;finished processing foo&apos;);
});
cargoQueue.push({name: &apos;bar&apos;}, function(err) {
    console.log(&apos;finished processing bar&apos;);
});
cargoQueue.push({name: &apos;baz&apos;}, function(err) {
    console.log(&apos;finished processing baz&apos;);
});
cargoQueue.push({name: &apos;boo&apos;}, function(err) {
    console.log(&apos;finished processing boo&apos;);
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="cargoQueue.js.html">cargoQueue.js</a>, <a href="cargoQueue.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#queue">async.queue</a></p></li>
        
            <li><p>async.cargo</p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="compose"><span class="type-signature">(static) </span>compose<span class="signature">(&#x2026;functions)</span><span class="type-signature"> &#x2192; {function}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import compose from &apos;async/compose&apos;;
</code></pre>
<p>Creates a function which is a composition of the passed asynchronous
functions. Each function consumes the return value of the function that
follows. Composing functions <code>f()</code>, <code>g()</code>, and <code>h()</code> would produce the result
of <code>f(g(h()))</code>, only this version uses callbacks to obtain the return values.</p>
<p>If the last argument to the composed function is not a function, a promise
is returned when you call it.</p>
<p>Each function is executed with the <code>this</code> binding of the composed function.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>functions</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>the asynchronous functions to compose</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>an asynchronous function that is the composed
asynchronous <code>functions</code></p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">function</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>function add1(n, callback) {
    setTimeout(function () {
        callback(null, n + 1);
    }, 10);
}

function mul3(n, callback) {
    setTimeout(function () {
        callback(null, n * 3);
    }, 10);
}

var add1mul3 = async.compose(mul3, add1);
add1mul3(4, function (err, result) {
    // result now equals 15
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="compose.js.html">compose.js</a>, <a href="compose.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="doUntil"><span class="type-signature">(static) </span>doUntil<span class="signature">(iteratee, test, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import doUntil from &apos;async/doUntil&apos;;
</code></pre>
<p>Like <a href="#doWhilst">&apos;doWhilst&apos;</a>, except the <code>test</code> is inverted. Note the
argument ordering differs from <code>until</code>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function which is called each time
<code>test</code> fails. Invoked with (callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>test</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>asynchronous truth test to perform after each
execution of <code>iteratee</code>. Invoked with (...args, callback), where <code>...args</code> are the
non-error args from the previous callback of <code>iteratee</code></p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after the test
function has passed and repeated execution of <code>iteratee</code> has stopped. <code>callback</code>
will be passed an error and any arguments passed to the final <code>iteratee</code>&apos;s
callback. Invoked with (err, [results]);</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="doUntil.js.html">doUntil.js</a>, <a href="doUntil.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#doWhilst">async.doWhilst</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="doWhilst"><span class="type-signature">(static) </span>doWhilst<span class="signature">(iteratee, test, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import doWhilst from &apos;async/doWhilst&apos;;
</code></pre>
<p>The post-check version of <a href="#whilst"><code>whilst</code></a>. To reflect the difference in
the order of operations, the arguments <code>test</code> and <code>iteratee</code> are switched.</p>
<p><code>doWhilst</code> is to <code>whilst</code> as <code>do while</code> is to <code>while</code> in plain JavaScript.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>A function which is called each time <code>test</code>
passes. Invoked with (callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>test</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>asynchronous truth test to perform after each
execution of <code>iteratee</code>. Invoked with (...args, callback), where <code>...args</code> are the
non-error args from the previous callback of <code>iteratee</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after the test
function has failed and repeated execution of <code>iteratee</code> has stopped.
<code>callback</code> will be passed an error and any arguments passed to the final
<code>iteratee</code>&apos;s callback. Invoked with (err, [results]);</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="doWhilst.js.html">doWhilst.js</a>, <a href="doWhilst.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#whilst">async.whilst</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="forever"><span class="type-signature">(static) </span>forever<span class="signature">(fn, errback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import forever from &apos;async/forever&apos;;
</code></pre>
<p>Calls the asynchronous function <code>fn</code> with a callback parameter that allows it
to call itself again, in series, indefinitely.
If an error is passed to the callback then <code>errback</code> is called with the
error, and execution stops, otherwise it will never be called.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fn</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>an async function to call repeatedly.
Invoked with (next).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>errback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>when <code>fn</code> passes an error to it&apos;s callback,
this function will be called, and execution stops. Invoked with (err).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise that rejects if an error occurs and an errback
is not passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>async.forever(
    function(next) {
        // next is suitable for passing to things that need a callback(err [, whatever]);
        // it will result in this function being called again.
    },
    function(err) {
        // if next is called with a value in its first parameter, it will appear
        // in here as &apos;err&apos;, and execution will stop.
    }
);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="forever.js.html">forever.js</a>, <a href="forever.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="parallel"><span class="type-signature">(static) </span>parallel<span class="signature">(tasks, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import parallel from &apos;async/parallel&apos;;
</code></pre>
<p>Run the <code>tasks</code> collection of functions in parallel, without waiting until
the previous function has completed. If any of the functions pass an error to
its callback, the main <code>callback</code> is immediately called with the value of the
error. Once the <code>tasks</code> have completed, the results are passed to the final
<code>callback</code> as an array.</p>
<p><strong>Note:</strong> <code>parallel</code> is about kicking-off I/O tasks in parallel, not about
parallel execution of code.  If your tasks do not use any timers or perform
any I/O, they will actually be executed in series.  Any synchronous setup
sections for each task will happen one after the other.  JavaScript remains
single-threaded.</p>
<p><strong>Hint:</strong> Use <a href="#reflect"><code>reflect</code></a> to continue the
execution of other tasks when a task fails.</p>
<p>It is also possible to use an object instead of an array. Each property will
be run as a function and the results will be passed to the final <code>callback</code>
as an object instead of an array. This can be a more readable way of handling
results from async.parallel.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection of
<a href="global.html">async functions</a> to run.
Each async function can complete with any number of optional <code>result</code> values.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>An optional callback to run once all the
functions have completed successfully. This function gets a results array
(or object) containing all the result arguments passed to the task callbacks.
Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is not passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>//Using Callbacks
async.parallel([
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;one&apos;);
        }, 200);
    },
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;two&apos;);
        }, 100);
    }
], function(err, results) {
    console.log(results);
    // results is equal to [&apos;one&apos;,&apos;two&apos;] even though
    // the second function had a shorter timeout.
});

// an example using an object instead of an array
async.parallel({
    one: function(callback) {
        setTimeout(function() {
            callback(null, 1);
        }, 200);
    },
    two: function(callback) {
        setTimeout(function() {
            callback(null, 2);
        }, 100);
    }
}, function(err, results) {
    console.log(results);
    // results is equal to: { one: 1, two: 2 }
});

//Using Promises
async.parallel([
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;one&apos;);
        }, 200);
    },
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;two&apos;);
        }, 100);
    }
]).then(results =&gt; {
    console.log(results);
    // results is equal to [&apos;one&apos;,&apos;two&apos;] even though
    // the second function had a shorter timeout.
}).catch(err =&gt; {
    console.log(err);
});

// an example using an object instead of an array
async.parallel({
    one: function(callback) {
        setTimeout(function() {
            callback(null, 1);
        }, 200);
    },
    two: function(callback) {
        setTimeout(function() {
            callback(null, 2);
        }, 100);
    }
}).then(results =&gt; {
    console.log(results);
    // results is equal to: { one: 1, two: 2 }
}).catch(err =&gt; {
    console.log(err);
});

//Using async/await
async () =&gt; {
    try {
        let results = await async.parallel([
            function(callback) {
                setTimeout(function() {
                    callback(null, &apos;one&apos;);
                }, 200);
            },
            function(callback) {
                setTimeout(function() {
                    callback(null, &apos;two&apos;);
                }, 100);
            }
        ]);
        console.log(results);
        // results is equal to [&apos;one&apos;,&apos;two&apos;] even though
        // the second function had a shorter timeout.
    }
    catch (err) {
        console.log(err);
    }
}

// an example using an object instead of an array
async () =&gt; {
    try {
        let results = await async.parallel({
            one: function(callback) {
                setTimeout(function() {
                    callback(null, 1);
                }, 200);
            },
           two: function(callback) {
                setTimeout(function() {
                    callback(null, 2);
                }, 100);
           }
        });
        console.log(results);
        // results is equal to: { one: 1, two: 2 }
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="parallel.js.html">parallel.js</a>, <a href="parallel.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="parallelLimit"><span class="type-signature">(static) </span>parallelLimit<span class="signature">(tasks, limit, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import parallelLimit from &apos;async/parallelLimit&apos;;
</code></pre>
<p>The same as <a href="#parallel"><code>parallel</code></a> but runs a maximum of <code>limit</code> async operations at a
time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection of
<a href="global.html">async functions</a> to run.
Each async function can complete with any number of optional <code>result</code> values.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>An optional callback to run once all the
functions have completed successfully. This function gets a results array
(or object) containing all the result arguments passed to the task callbacks.
Invoked with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is not passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="parallelLimit.js.html">parallelLimit.js</a>, <a href="parallelLimit.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#parallel">async.parallel</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="priorityQueue"><span class="type-signature">(static) </span>priorityQueue<span class="signature">(worker, concurrency)</span><span class="type-signature"> &#x2192; {<a href="#QueueObject">QueueObject</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import priorityQueue from &apos;async/priorityQueue&apos;;
</code></pre>
<p>The same as <a href="#queue">async.queue</a> only tasks are assigned a priority and
completed in ascending priority order.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>worker</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function for processing a queued task.
If you want to handle errors from an individual task, pass a callback to
<code>q.push()</code>.
Invoked with (task, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>concurrency</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>An <code>integer</code> for determining how many <code>worker</code>
functions should be run in parallel.  If omitted, the concurrency defaults to
<code>1</code>.  If the concurrency is <code>0</code>, an error is thrown.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A priorityQueue object to manage the tasks. There are three
differences between <code>queue</code> and <code>priorityQueue</code> objects:</p>
<ul>
<li><code>push(task, priority, [callback])</code> - <code>priority</code> should be a number. If an
array of <code>tasks</code> is given, all tasks will be assigned the same priority.</li>
<li><code>pushAsync(task, priority, [callback])</code> - the same as <code>priorityQueue.push</code>,
except this returns a promise that rejects if an error occurs.</li>
<li>The <code>unshift</code> and <code>unshiftAsync</code> methods were removed.</li>
</ul>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="#QueueObject">QueueObject</a></span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="priorityQueue.js.html">priorityQueue.js</a>, <a href="priorityQueue.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#queue">async.queue</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="queue"><span class="type-signature">(static) </span>queue<span class="signature">(worker, concurrency<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {<a href="#QueueObject">QueueObject</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import queue from &apos;async/queue&apos;;
</code></pre>
<p>Creates a <code>queue</code> object with the specified <code>concurrency</code>. Tasks added to the
<code>queue</code> are processed in parallel (up to the <code>concurrency</code> limit). If all
<code>worker</code>s are in progress, the task is queued until one becomes available.
Once a <code>worker</code> completes a <code>task</code>, that <code>task</code>&apos;s callback is called.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>worker</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>An async function for processing a queued task.
If you want to handle errors from an individual task, pass a callback to
<code>q.push()</code>. Invoked with (task, callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>concurrency</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                    1
                
                </td>
            

            <td class="description last"><p>An <code>integer</code> for determining how many
<code>worker</code> functions should be run in parallel.  If omitted, the concurrency
defaults to <code>1</code>.  If the concurrency is <code>0</code>, an error is thrown.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>A queue object to manage the tasks. Callbacks can be
attached as certain properties to listen for specific events during the
lifecycle of the queue.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="#QueueObject">QueueObject</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// create a queue object with concurrency 2
var q = async.queue(function(task, callback) {
    console.log(&apos;hello &apos; + task.name);
    callback();
}, 2);

// assign a callback
q.drain(function() {
    console.log(&apos;all items have been processed&apos;);
});
// or await the end
await q.drain()

// assign an error callback
q.error(function(err, task) {
    console.error(&apos;task experienced an error&apos;);
});

// add some items to the queue
q.push({name: &apos;foo&apos;}, function(err) {
    console.log(&apos;finished processing foo&apos;);
});
// callback is optional
q.push({name: &apos;bar&apos;});

// add some items to the queue (batch-wise)
q.push([{name: &apos;baz&apos;},{name: &apos;bay&apos;},{name: &apos;bax&apos;}], function(err) {
    console.log(&apos;finished processing item&apos;);
});

// add some items to the front of the queue
q.unshift({name: &apos;bar&apos;}, function (err) {
    console.log(&apos;finished processing bar&apos;);
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line89">line 89</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="race"><span class="type-signature">(static) </span>race<span class="signature">(tasks, callback)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import race from &apos;async/race&apos;;
</code></pre>
<p>Runs the <code>tasks</code> array of functions in parallel, without waiting until the
previous function has completed. Once any of the <code>tasks</code> complete or pass an
error to its callback, the main <code>callback</code> is immediately called. It&apos;s
equivalent to <code>Promise.race()</code>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>


            

            
            </td>

            

            <td class="description last"><p>An array containing <a href="global.html">async functions</a>
to run. Each function can complete with an optional <code>result</code> value.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>A callback to run once any of the functions have
completed. This function gets an error or result from the first function that
completed. Invoked with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>async.race([
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;one&apos;);
        }, 200);
    },
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;two&apos;);
        }, 100);
    }
],
// main callback
function(err, result) {
    // the result will be equal to &apos;two&apos; as it finishes earlier
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="race.js.html">race.js</a>, <a href="race.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="retry"><span class="type-signature">(static) </span>retry<span class="signature">(opts<span class="signature-attributes">opt</span>, task, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import retry from &apos;async/retry&apos;;
</code></pre>
<p>Attempts to get a successful response from <code>task</code> no more than <code>times</code> times
before returning an error. If the task is successful, the <code>callback</code> will be
passed the result of the successful task. If all attempts fail, the callback
will be passed the error and result (if any) of the final attempt.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>opts</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>
|

<span class="param-type">number</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                    {times: 5, interval: 0}| 5
                
                </td>
            

            <td class="description last"><p>Can be either an
object with <code>times</code> and <code>interval</code> or a number.</p>
<ul>
<li><code>times</code> - The number of attempts to make before giving up.  The default
is <code>5</code>.</li>
<li><code>interval</code> - The time to wait between retries, in milliseconds.  The
default is <code>0</code>. The interval may also be specified as a function of the
retry count (see example).</li>
<li><code>errorFilter</code> - An optional synchronous function that is invoked on
erroneous result. If it returns <code>true</code> the retry attempts will continue;
if the function returns <code>false</code> the retry flow is aborted with the current
attempt&apos;s error and result being returned to the final callback.
Invoked with (err).</li>
<li>If <code>opts</code> is a number, the number specifies the number of times to retry,
with the default interval of <code>0</code>.</li>
</ul></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>task</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>An async function to retry.
Invoked with (callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>An optional callback which is called when the
task has succeeded, or after the final failed attempt. It receives the <code>err</code>
and <code>result</code> arguments of the last attempt at completing the <code>task</code>. Invoked
with (err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise if no callback provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// The `retry` function can be used as a stand-alone control flow by passing
// a callback, as shown below:

// try calling apiMethod 3 times
async.retry(3, apiMethod, function(err, result) {
    // do something with the result
});

// try calling apiMethod 3 times, waiting 200 ms between each retry
async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
    // do something with the result
});

// try calling apiMethod 10 times with exponential backoff
// (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
async.retry({
  times: 10,
  interval: function(retryCount) {
    return 50 * Math.pow(2, retryCount);
  }
}, apiMethod, function(err, result) {
    // do something with the result
});

// try calling apiMethod the default 5 times no delay between each retry
async.retry(apiMethod, function(err, result) {
    // do something with the result
});

// try calling apiMethod only when error condition satisfies, all other
// errors will abort the retry control flow and return to final callback
async.retry({
  errorFilter: function(err) {
    return err.message === &apos;Temporary error&apos;; // only retry on a specific error
  }
}, apiMethod, function(err, result) {
    // do something with the result
});

// to retry individual methods that are not as reliable within other
// control flow functions, use the `retryable` wrapper:
async.auto({
    users: api.getUsers.bind(api),
    payments: async.retryable(3, api.getPayments.bind(api))
}, function(err, results) {
    // do something with the results
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="retry.js.html">retry.js</a>, <a href="retry.js.html#line10">line 10</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#retryable">async.retryable</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="retryable"><span class="type-signature">(static) </span>retryable<span class="signature">(opts<span class="signature-attributes">opt</span>, task)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import retryable from &apos;async/retryable&apos;;
</code></pre>
<p>A close relative of <a href="#retry"><code>retry</code></a>.  This method
wraps a task and makes it retryable, rather than immediately calling it
with retries.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        
        <th>Default</th>
        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>opts</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>
|

<span class="param-type">number</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            
                <td class="default">
                
                    {times: 5, interval: 0}| 5
                
                </td>
            

            <td class="description last"><p>optional
options, exactly the same as from <code>retry</code>, except for a <code>opts.arity</code> that
is the arity of the <code>task</code> function, defaulting to <code>task.length</code></p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>task</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            
                <td class="default">
                
                </td>
            

            <td class="description last"><p>the asynchronous function to wrap.
This function will be passed any arguments passed to the returned wrapper.
Invoked with (...args, callback).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>The wrapped function, which when invoked, will
retry on an error, based on the parameters specified in <code>opts</code>.
This function will accept the same parameters as <code>task</code>.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>async.auto({
    dep1: async.retryable(3, getFromFlakyService),
    process: [&quot;dep1&quot;, async.retryable(3, function (results, cb) {
        maybeProcessData(results.dep1, cb);
    })]
}, callback);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="retryable.js.html">retryable.js</a>, <a href="retryable.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#retry">async.retry</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="seq"><span class="type-signature">(static) </span>seq<span class="signature">(&#x2026;functions)</span><span class="type-signature"> &#x2192; {function}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import seq from &apos;async/seq&apos;;
</code></pre>
<p>Version of the compose function that is more natural to read. Each function
consumes the return value of the previous function. It is the equivalent of
<a href="#compose">compose</a> with the arguments reversed.</p>
<p>Each function is executed with the <code>this</code> binding of the composed function.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>functions</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>the asynchronous functions to compose</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a function that composes the <code>functions</code> in order</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">function</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// Requires lodash (or underscore), express3 and dresende&apos;s orm2.
// Part of an app, that fetches cats of the logged user.
// This example uses `seq` function to avoid overnesting and error
// handling clutter.
app.get(&apos;/cats&apos;, function(request, response) {
    var User = request.models.User;
    async.seq(
        User.get.bind(User),  // &apos;User.get&apos; has signature (id, callback(err, data))
        function(user, fn) {
            user.getCats(fn);      // &apos;getCats&apos; has signature (callback(err, data))
        }
    )(req.session.user_id, function (err, cats) {
        if (err) {
            console.error(err);
            response.json({ status: &apos;error&apos;, message: err.message });
        } else {
            response.json({ status: &apos;ok&apos;, message: &apos;Cats found&apos;, data: cats });
        }
    });
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="seq.js.html">seq.js</a>, <a href="seq.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#compose">async.compose</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="series"><span class="type-signature">(static) </span>series<span class="signature">(tasks, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import series from &apos;async/series&apos;;
</code></pre>
<p>Run the functions in the <code>tasks</code> collection in series, each one running once
the previous function has completed. If any functions in the series pass an
error to its callback, no more functions are run, and <code>callback</code> is
immediately called with the value of the error. Otherwise, <code>callback</code>
receives an array of results when <code>tasks</code> have completed.</p>
<p>It is also possible to use an object instead of an array. Each property will
be run as a function, and the results will be passed to the final <code>callback</code>
as an object instead of an array. This can be a more readable way of handling
results from async.series.</p>
<p><strong>Note</strong> that while many implementations preserve the order of object
properties, the <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-8.6">ECMAScript Language Specification</a>
explicitly states that</p>
<blockquote>
<p>The mechanics and order of enumerating the properties is not specified.</p>
</blockquote>
<p>So if you rely on the order in which your series of functions are executed,
and want this to work on all platforms, consider using an array.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection containing
<a href="global.html">async functions</a> to run in series.
Each function can complete with any number of optional <code>result</code> values.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>An optional callback to run once all the
functions have completed. This function gets a results array (or object)
containing all the result arguments passed to the <code>task</code> callbacks. Invoked
with (err, result).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>//Using Callbacks
async.series([
    function(callback) {
        setTimeout(function() {
            // do some async task
            callback(null, &apos;one&apos;);
        }, 200);
    },
    function(callback) {
        setTimeout(function() {
            // then do another async task
            callback(null, &apos;two&apos;);
        }, 100);
    }
], function(err, results) {
    console.log(results);
    // results is equal to [&apos;one&apos;,&apos;two&apos;]
});

// an example using objects instead of arrays
async.series({
    one: function(callback) {
        setTimeout(function() {
            // do some async task
            callback(null, 1);
        }, 200);
    },
    two: function(callback) {
        setTimeout(function() {
            // then do another async task
            callback(null, 2);
        }, 100);
    }
}, function(err, results) {
    console.log(results);
    // results is equal to: { one: 1, two: 2 }
});

//Using Promises
async.series([
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;one&apos;);
        }, 200);
    },
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;two&apos;);
        }, 100);
    }
]).then(results =&gt; {
    console.log(results);
    // results is equal to [&apos;one&apos;,&apos;two&apos;]
}).catch(err =&gt; {
    console.log(err);
});

// an example using an object instead of an array
async.series({
    one: function(callback) {
        setTimeout(function() {
            // do some async task
            callback(null, 1);
        }, 200);
    },
    two: function(callback) {
        setTimeout(function() {
            // then do another async task
            callback(null, 2);
        }, 100);
    }
}).then(results =&gt; {
    console.log(results);
    // results is equal to: { one: 1, two: 2 }
}).catch(err =&gt; {
    console.log(err);
});

//Using async/await
async () =&gt; {
    try {
        let results = await async.series([
            function(callback) {
                setTimeout(function() {
                    // do some async task
                    callback(null, &apos;one&apos;);
                }, 200);
            },
            function(callback) {
                setTimeout(function() {
                    // then do another async task
                    callback(null, &apos;two&apos;);
                }, 100);
            }
        ]);
        console.log(results);
        // results is equal to [&apos;one&apos;,&apos;two&apos;]
    }
    catch (err) {
        console.log(err);
    }
}

// an example using an object instead of an array
async () =&gt; {
    try {
        let results = await async.parallel({
            one: function(callback) {
                setTimeout(function() {
                    // do some async task
                    callback(null, 1);
                }, 200);
            },
           two: function(callback) {
                setTimeout(function() {
                    // then do another async task
                    callback(null, 2);
                }, 100);
           }
        });
        console.log(results);
        // results is equal to: { one: 1, two: 2 }
    }
    catch (err) {
        console.log(err);
    }
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="series.js.html">series.js</a>, <a href="series.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="times"><span class="type-signature">(static) </span>times<span class="signature">(n, iteratee, callback)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import times from &apos;async/times&apos;;
</code></pre>
<p>Calls the <code>iteratee</code> function <code>n</code> times, and accumulates results in the same
manner you would use with <a href="#map">map</a>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>n</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The number of times to run the function.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The async function to call <code>n</code> times.
Invoked with the iteration index and a callback: (n, next).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>see <a href="#map">map</a>.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// Pretend this is some complicated async factory
var createUser = function(id, callback) {
    callback(null, {
        id: &apos;user&apos; + id
    });
};

// generate 5 users
async.times(5, function(n, next) {
    createUser(n, function(err, user) {
        next(err, user);
    });
}, function(err, users) {
    // we should now have 5 users
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="times.js.html">times.js</a>, <a href="times.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#map">async.map</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="timesLimit"><span class="type-signature">(static) </span>timesLimit<span class="signature">(count, limit, iteratee, callback)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import timesLimit from &apos;async/timesLimit&apos;;
</code></pre>
<p>The same as <a href="#times">times</a> but runs a maximum of <code>limit</code> async operations at a
time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>count</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The number of times to run the function.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>limit</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The maximum number of async operations at a time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The async function to call <code>n</code> times.
Invoked with the iteration index and a callback: (n, next).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>see <a href="#map">async.map</a>.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="timesLimit.js.html">timesLimit.js</a>, <a href="timesLimit.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#times">async.times</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="timesSeries"><span class="type-signature">(static) </span>timesSeries<span class="signature">(n, iteratee, callback)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import timesSeries from &apos;async/timesSeries&apos;;
</code></pre>
<p>The same as <a href="#times">times</a> but runs only a single async operation at a time.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>n</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The number of times to run the function.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The async function to call <code>n</code> times.
Invoked with the iteration index and a callback: (n, next).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>see <a href="#map">map</a>.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is provided</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="timesSeries.js.html">timesSeries.js</a>, <a href="timesSeries.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#times">async.times</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="tryEach"><span class="type-signature">(static) </span>tryEach<span class="signature">(tasks, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import tryEach from &apos;async/tryEach&apos;;
</code></pre>
<p>It runs each task in series but stops whenever any of the functions were
successful. If one of the tasks were successful, the <code>callback</code> will be
passed the result of the successful task. If all tasks fail, the callback
will be passed the error and result (if any) of the final attempt.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Iterable</span>
|

<span class="param-type">AsyncIterable</span>
|

<span class="param-type">Object</span>


            

            
            </td>

            

            <td class="description last"><p>A collection containing functions to
run, each function is passed a <code>callback(err, result)</code> it must call on
completion with an error <code>err</code> (which can be <code>null</code>) and an optional <code>result</code>
value.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>An optional callback which is called when one
of the tasks has succeeded, or all have failed. It receives the <code>err</code> and
<code>result</code> arguments of the last attempt at completing the <code>task</code>. Invoked with
(err, results).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>async.tryEach([
    function getDataFromFirstWebsite(callback) {
        // Try getting the data from the first website
        callback(err, data);
    },
    function getDataFromSecondWebsite(callback) {
        // First website failed,
        // Try getting the data from the backup website
        callback(err, data);
    }
],
// optional callback
function(err, results) {
    Now do something with the data.
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="tryEach.js.html">tryEach.js</a>, <a href="tryEach.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="until"><span class="type-signature">(static) </span>until<span class="signature">(test, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import until from &apos;async/until&apos;;
</code></pre>
<p>Repeatedly call <code>iteratee</code> until <code>test</code> returns <code>true</code>. Calls <code>callback</code> when
stopped, or an error occurs. <code>callback</code> will be passed an error and any
arguments passed to the final <code>iteratee</code>&apos;s callback.</p>
<p>The inverse of <a href="#whilst">whilst</a>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>test</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>asynchronous truth test to perform before each
execution of <code>iteratee</code>. Invoked with (callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function which is called each time
<code>test</code> fails. Invoked with (callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after the test
function has passed and repeated execution of <code>iteratee</code> has stopped. <code>callback</code>
will be passed an error and any arguments passed to the final <code>iteratee</code>&apos;s
callback. Invoked with (err, [results]);</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is not passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>const results = []
let finished = false
async.until(function test(cb) {
    cb(null, finished)
}, function iter(next) {
    fetchPage(url, (err, body) =&gt; {
        if (err) return next(err)
        results = results.concat(body.objects)
        finished = !!body.next
        next(err)
    })
}, function done (err) {
    // all pages have been fetched
})</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="until.js.html">until.js</a>, <a href="until.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#whilst">async.whilst</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="waterfall"><span class="type-signature">(static) </span>waterfall<span class="signature">(tasks, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import waterfall from &apos;async/waterfall&apos;;
</code></pre>
<p>Runs the <code>tasks</code> array of functions in series, each passing their results to
the next in the array. However, if any of the <code>tasks</code> pass an error to their
own callback, the next function is not executed, and the main <code>callback</code> is
immediately called with the error.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>


            

            
            </td>

            

            <td class="description last"><p>An array of <a href="global.html">async functions</a>
to run.
Each function should complete with any number of <code>result</code> values.
The <code>result</code> values will be passed as arguments, in order, to the next task.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>An optional callback to run once all the
functions have completed. This will be passed the results of the last task&apos;s
callback. Invoked with (err, [results]).</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if a callback is omitted</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>async.waterfall([
    function(callback) {
        callback(null, &apos;one&apos;, &apos;two&apos;);
    },
    function(arg1, arg2, callback) {
        // arg1 now equals &apos;one&apos; and arg2 now equals &apos;two&apos;
        callback(null, &apos;three&apos;);
    },
    function(arg1, callback) {
        // arg1 now equals &apos;three&apos;
        callback(null, &apos;done&apos;);
    }
], function (err, result) {
    // result now equals &apos;done&apos;
});

// Or, with named functions:
async.waterfall([
    myFirstFunction,
    mySecondFunction,
    myLastFunction,
], function (err, result) {
    // result now equals &apos;done&apos;
});
function myFirstFunction(callback) {
    callback(null, &apos;one&apos;, &apos;two&apos;);
}
function mySecondFunction(arg1, arg2, callback) {
    // arg1 now equals &apos;one&apos; and arg2 now equals &apos;two&apos;
    callback(null, &apos;three&apos;);
}
function myLastFunction(arg1, callback) {
    // arg1 now equals &apos;three&apos;
    callback(null, &apos;done&apos;);
}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="waterfall.js.html">waterfall.js</a>, <a href="waterfall.js.html#line6">line 6</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="whilst"><span class="type-signature">(static) </span>whilst<span class="signature">(test, iteratee, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {Promise}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import whilst from &apos;async/whilst&apos;;
</code></pre>
<p>Repeatedly call <code>iteratee</code>, while <code>test</code> returns <code>true</code>. Calls <code>callback</code> when
stopped, or an error occurs.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>test</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>asynchronous truth test to perform before each
execution of <code>iteratee</code>. Invoked with (callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>iteratee</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>An async function which is called each time
<code>test</code> passes. Invoked with (callback).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>A callback which is called after the test
function has failed and repeated execution of <code>iteratee</code> has stopped. <code>callback</code>
will be passed an error and any arguments passed to the final <code>iteratee</code>&apos;s
callback. Invoked with (err, [results]);</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a promise, if no callback is passed</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Promise</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>var count = 0;
async.whilst(
    function test(cb) { cb(null, count &lt; 5); },
    function iter(callback) {
        count++;
        setTimeout(function() {
            callback(null, count);
        }, 1000);
    },
    function (err, n) {
        // 5 seconds have passed, n = 5
    }
);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="whilst.js.html">whilst.js</a>, <a href="whilst.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
    

    
        <h3 class="subsection-title">Type Definitions</h3>

        
                
<h4 class="name" id="QueueObject">QueueObject</h4>




<div class="description">
    <pre class="prettyprint source"><code>import queue from &apos;async/queue&apos;;
</code></pre>
<p>A queue of tasks for the worker function to complete.</p>
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">Iterable</span>


        </li>
    </ul>





    <h5 class="subsection-title">Properties:</h5>

    

<table class="props">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>length</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function returning the number of items
waiting to be processed. Invoke with <code>queue.length()</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>started</code></td>
            

            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>

            

            

            <td class="description last"><p>a boolean indicating whether or not any
items have been pushed and processed by the queue.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>running</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function returning the number of items
currently being processed. Invoke with <code>queue.running()</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>workersList</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function returning the array of items
currently being processed. Invoke with <code>queue.workersList()</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>idle</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function returning false if there are items
waiting or being processed, or true if not. Invoke with <code>queue.idle()</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>concurrency</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last"><p>an integer for determining how many <code>worker</code>
functions should be run in parallel. This property can be changed after a
<code>queue</code> is created to alter the concurrency on-the-fly.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>payload</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last"><p>an integer that specifies how many items are
passed to the worker function at a time. only applies if this is a
<a href="#cargo">cargo</a> object</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>push</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            
            </td>

            

            

            <td class="description last"><p>add a new task to the <code>queue</code>. Calls <code>callback</code>
once the <code>worker</code> has finished processing the task. Instead of a single task,
a <code>tasks</code> array can be submitted. The respective callback is used for every
task in the list. Invoke with <code>queue.push(task, [callback])</code>,</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>unshift</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            
            </td>

            

            

            <td class="description last"><p>add a new task to the front of the <code>queue</code>.
Invoke with <code>queue.unshift(task, [callback])</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>pushAsync</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            
            </td>

            

            

            <td class="description last"><p>the same as <code>q.push</code>, except this returns
a promise that rejects if an error occurs.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>unshiftAsync</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            
            </td>

            

            

            <td class="description last"><p>the same as <code>q.unshift</code>, except this returns
a promise that rejects if an error occurs.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>remove</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>remove items from the queue that match a test
function.  The test function will be passed an object with a <code>data</code> property,
and a <code>priority</code> property, if this is a
<a href="#priorityQueue">priorityQueue</a> object.
Invoked with <code>queue.remove(testFn)</code>, where <code>testFn</code> is of the form
<code>function ({data, priority}) {}</code> and returns a Boolean.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>saturated</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that sets a callback that is
called when the number of running workers hits the <code>concurrency</code> limit, and
further tasks will be queued.  If the callback is omitted, <code>q.saturated()</code>
returns a promise for the next occurrence.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>unsaturated</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that sets a callback that is
called when the number of running workers is less than the <code>concurrency</code> &amp;
<code>buffer</code> limits, and further tasks will not be queued. If the callback is
omitted, <code>q.unsaturated()</code> returns a promise for the next occurrence.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>buffer</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last"><p>A minimum threshold buffer in order to say that
the <code>queue</code> is <code>unsaturated</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>empty</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that sets a callback that is called
when the last item from the <code>queue</code> is given to a <code>worker</code>. If the callback
is omitted, <code>q.empty()</code> returns a promise for the next occurrence.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>drain</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that sets a callback that is called
when the last item from the <code>queue</code> has returned from the <code>worker</code>. If the
callback is omitted, <code>q.drain()</code> returns a promise for the next occurrence.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>error</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that sets a callback that is called
when a task errors. Has the signature <code>function(error, task)</code>. If the
callback is omitted, <code>error()</code> returns a promise that rejects on the next
error.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>paused</code></td>
            

            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>

            

            

            <td class="description last"><p>a boolean for determining whether the queue is
in a paused state.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>pause</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that pauses the processing of tasks
until <code>resume()</code> is called. Invoke with <code>queue.pause()</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>resume</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that resumes the processing of
queued tasks when the queue is paused. Invoke with <code>queue.resume()</code>.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>kill</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            
            </td>

            

            

            <td class="description last"><p>a function that removes the <code>drain</code> callback and
empties remaining tasks from the queue forcing it to go idle. No more tasks
should be pushed to the queue after calling this function. Invoke with <code>queue.kill()</code>.</p></td>
        </tr>

    
    </tbody>
</table>




<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>





    <h5>Example</h5>
    
    <pre class="prettyprint"><code>const q = async.queue(worker, 2)
q.push(item1)
q.push(item2)
q.push(item3)
// queues are iterable, spread into an array to inspect
const items = [...q] // [item1, item2, item3]
// or use for of
for (let item of q) {
    console.log(item)
}

q.drain(() =&gt; {
    console.log(&apos;all done&apos;)
})
// or
await q.drain()</code></pre>



            
    

    
</article>

</section>




    
        
        <h1 class="page-title" id="utils">Utils</h1>
        

        




<section>

<header>
    
        
            
        
    
</header>

<article>
    <div class="container-overview">
    
        
            <div class="description"><p>A collection of <code>async</code> utility functions.</p></div>
        

        
            





















<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="index.js.html">index.js</a>, <a href="index.js.html#line61">line 61</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
    
    </div>

    

    

    

     

    

    

    
        <h3 class="subsection-title">Methods</h3>

        
            

    

    <h4 class="name" id="apply"><span class="type-signature">(static) </span>apply<span class="signature">(fn)</span><span class="type-signature"> &#x2192; {function}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import apply from &apos;async/apply&apos;;
</code></pre>
<p>Creates a continuation function with some arguments already applied.</p>
<p>Useful as a shorthand when combined with other control flow functions. Any
arguments passed to the returned function are added to the arguments
originally passed to apply.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fn</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>The function you want to eventually apply all
arguments to. Invokes with (arguments...).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>arguments...</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>Any number of arguments to automatically apply
when the continuation is called.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>the partially-applied function</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">function</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// using apply
async.parallel([
    async.apply(fs.writeFile, &apos;testfile1&apos;, &apos;test1&apos;),
    async.apply(fs.writeFile, &apos;testfile2&apos;, &apos;test2&apos;)
]);


// the same process without using apply
async.parallel([
    function(callback) {
        fs.writeFile(&apos;testfile1&apos;, &apos;test1&apos;, callback);
    },
    function(callback) {
        fs.writeFile(&apos;testfile2&apos;, &apos;test2&apos;, callback);
    }
]);

// It&apos;s possible to pass any number of additional arguments when calling the
// continuation:

node&gt; var fn = async.apply(sys.puts, &apos;one&apos;);
node&gt; fn(&apos;two&apos;, &apos;three&apos;);
one
two
three</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="apply.js.html">apply.js</a>, <a href="apply.js.html#line1">line 1</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="asyncify"><span class="type-signature">(static) </span>asyncify<span class="signature">(func)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import asyncify from &apos;async/asyncify&apos;;
</code></pre>
<p>Take a sync function and make it async, passing its return value to a
callback. This is useful for plugging sync functions into a waterfall,
series, or other async functions. Any arguments passed to the generated
function will be passed to the wrapped function (except for the final
callback argument). Errors thrown will be passed to the callback.</p>
<p>If the function passed to <code>asyncify</code> returns a Promise, that promises&apos;s
resolved/rejected state will be used to call the callback, rather than simply
the synchronous return value.</p>
<p>This also means you can asyncify ES2017 <code>async</code> functions.</p>
</div>



    <dl class="details alias-details">
        <dt class="tag-alias">Alias:</dt>
        <dd class="tag-alias"><ul class="dummy"><li>wrapSync</li></ul></dd>
    </dl>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>func</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>The synchronous function, or Promise-returning
function to convert to an <a href="global.html">AsyncFunction</a>.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>An asynchronous wrapper of the <code>func</code>. To be
invoked with <code>(args..., callback)</code>.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// passing a regular synchronous function
async.waterfall([
    async.apply(fs.readFile, filename, &quot;utf8&quot;),
    async.asyncify(JSON.parse),
    function (data, next) {
        // data is the result of parsing the text.
        // If there was a parsing error, it would have been caught.
    }
], callback);

// passing a function returning a promise
async.waterfall([
    async.apply(fs.readFile, filename, &quot;utf8&quot;),
    async.asyncify(function (contents) {
        return db.model.create(contents);
    }),
    function (model, next) {
        // `model` is the instantiated model object.
        // If there was an error, this function would be skipped.
    }
], callback);

// es2017 example, though `asyncify` is not needed if your JS environment
// supports async functions out of the box
var q = async.queue(async.asyncify(async function(file) {
    var intermediateStep = await processFile(file);
    return await somePromise(intermediateStep)
}));

q.push(files);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="asyncify.js.html">asyncify.js</a>, <a href="asyncify.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="constant"><span class="type-signature">(static) </span>constant<span class="signature">()</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import constant from &apos;async/constant&apos;;
</code></pre>
<p>Returns a function that when called, calls-back with the values provided.
Useful as the first function in a <a href="#waterfall"><code>waterfall</code></a>, or for plugging values in to
<a href="#auto"><code>auto</code></a>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>arguments...</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>Any number of arguments to automatically invoke
callback with.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>Returns a function that when invoked, automatically
invokes the callback with the previous given arguments.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>async.waterfall([
    async.constant(42),
    function (value, next) {
        // value === 42
    },
    //...
], callback);

async.waterfall([
    async.constant(filename, &quot;utf8&quot;),
    fs.readFile,
    function (fileData, next) {
        //...
    }
    //...
], callback);

async.auto({
    hostname: async.constant(&quot;https://server.net/&quot;),
    port: findFreePort,
    launchServer: [&quot;hostname&quot;, &quot;port&quot;, function (options, cb) {
        startServer(options, cb);
    }],
    //...
}, callback);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="constant.js.html">constant.js</a>, <a href="constant.js.html#line1">line 1</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="dir"><span class="type-signature">(static) </span>dir<span class="signature">(function)</span><span class="type-signature"></span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import dir from &apos;async/dir&apos;;
</code></pre>
<p>Logs the result of an <a href="global.html"><code>async</code> function</a> to the
<code>console</code> using <code>console.dir</code> to display the properties of the resulting object.
Only works in Node.js or in browsers that support <code>console.dir</code> and
<code>console.error</code> (such as FF and Chrome).
If multiple arguments are returned from the async function,
<code>console.dir</code> is called on each argument in order.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>function</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The function you want to eventually apply
all arguments to.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>arguments...</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>Any number of arguments to apply to the function.</p></td>
        </tr>

    
    </tbody>
</table>






    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// in a module
var hello = function(name, callback) {
    setTimeout(function() {
        callback(null, {hello: name});
    }, 1000);
};

// in the node repl
node&gt; async.dir(hello, &apos;world&apos;);
{hello: &apos;world&apos;}</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="dir.js.html">dir.js</a>, <a href="dir.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="ensureAsync"><span class="type-signature">(static) </span>ensureAsync<span class="signature">(fn)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import ensureAsync from &apos;async/ensureAsync&apos;;
</code></pre>
<p>Wrap an async function and ensure it calls its callback on a later tick of
the event loop.  If the function already calls its callback on a next tick,
no extra deferral is added. This is useful for preventing stack overflows
(<code>RangeError: Maximum call stack size exceeded</code>) and generally keeping
<a href="http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony">Zalgo</a>
contained. ES2017 <code>async</code> functions are returned as-is -- they are immune
to Zalgo&apos;s corrupting influences, as they always resolve on a later tick.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fn</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>an async function, one that expects a node-style
callback as its last argument.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>Returns a wrapped function with the exact same call
signature as the function passed in.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>function sometimesAsync(arg, callback) {
    if (cache[arg]) {
        return callback(null, cache[arg]); // this would be synchronous!!
    } else {
        doSomeIO(arg, callback); // this IO would be asynchronous
    }
}

// this has a risk of stack overflows if many results are cached in a row
async.mapSeries(args, sometimesAsync, done);

// this will defer sometimesAsync&apos;s callback if necessary,
// preventing stack overflows
async.mapSeries(args, async.ensureAsync(sometimesAsync), done);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="ensureAsync.js.html">ensureAsync.js</a>, <a href="ensureAsync.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="log"><span class="type-signature">(static) </span>log<span class="signature">(function)</span><span class="type-signature"></span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import log from &apos;async/log&apos;;
</code></pre>
<p>Logs the result of an <code>async</code> function to the <code>console</code>. Only works in
Node.js or in browsers that support <code>console.log</code> and <code>console.error</code> (such
as FF and Chrome). If multiple arguments are returned from the async
function, <code>console.log</code> is called on each argument in order.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>function</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The function you want to eventually apply
all arguments to.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>arguments...</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>Any number of arguments to apply to the function.</p></td>
        </tr>

    
    </tbody>
</table>






    <h5>Example</h5>
    
    <pre class="prettyprint"><code>// in a module
var hello = function(name, callback) {
    setTimeout(function() {
        callback(null, &apos;hello &apos; + name);
    }, 1000);
};

// in the node repl
node&gt; async.log(hello, &apos;world&apos;);
&apos;hello world&apos;</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="log.js.html">log.js</a>, <a href="log.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="memoize"><span class="type-signature">(static) </span>memoize<span class="signature">(fn, hasher)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import memoize from &apos;async/memoize&apos;;
</code></pre>
<p>Caches the results of an async function. When creating a hash to store
function results against, the callback is omitted from the hash and an
optional hash function can be used.</p>
<p><strong>Note: if the async function errs, the result will not be cached and
subsequent calls will call the wrapped function.</strong></p>
<p>If no hash function is specified, the first argument is used as a hash key,
which may work reasonably if it is a string or a data type that converts to a
distinct string. Note that objects and arrays will not behave reasonably.
Neither will cases where the other arguments are significant. In such cases,
specify your own hash function.</p>
<p>The cache of results is exposed as the <code>memo</code> property of the function
returned by <code>memoize</code>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fn</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The async function to proxy and cache results from.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>hasher</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>An optional function for generating a custom hash
for storing results. It has all the arguments applied to it apart from the
callback, and must be synchronous.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a memoized version of <code>fn</code></p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>var slow_fn = function(name, callback) {
    // do something
    callback(null, result);
};
var fn = async.memoize(slow_fn);

// fn can now be used as if it were slow_fn
fn(&apos;some name&apos;, function() {
    // callback
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="memoize.js.html">memoize.js</a>, <a href="memoize.js.html#line5">line 5</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="nextTick"><span class="type-signature">(static) </span>nextTick<span class="signature">(callback)</span><span class="type-signature"></span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import nextTick from &apos;async/nextTick&apos;;
</code></pre>
<p>Calls <code>callback</code> on a later loop around the event loop. In Node.js this just
calls <code>process.nextTick</code>.  In the browser it will use <code>setImmediate</code> if
available, otherwise <code>setTimeout(callback, 0)</code>, which means other higher
priority events may precede the execution of <code>callback</code>.</p>
<p>This is used internally for browser-compatibility purposes.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>The function to call on a later loop around
the event loop. Invoked with (args...).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>args...</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>any number of additional arguments to pass to the
callback on the next tick.</p></td>
        </tr>

    
    </tbody>
</table>






    <h5>Example</h5>
    
    <pre class="prettyprint"><code>var call_order = [];
async.nextTick(function() {
    call_order.push(&apos;two&apos;);
    // call_order now equals [&apos;one&apos;,&apos;two&apos;]
});
call_order.push(&apos;one&apos;);

async.setImmediate(function (a, b, c) {
    // a, b, and c equal 1, 2, and 3
}, 1, 2, 3);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nextTick.js.html">nextTick.js</a>, <a href="nextTick.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#setImmediate">async.setImmediate</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="reflect"><span class="type-signature">(static) </span>reflect<span class="signature">(fn)</span><span class="type-signature"> &#x2192; {function}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import reflect from &apos;async/reflect&apos;;
</code></pre>
<p>Wraps the async function in another function that always completes with a
result object, even when it errors.</p>
<p>The result object has either the property <code>error</code> or <code>value</code>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fn</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The async function you want to wrap</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <ul>
<li>A function that always passes null to it&apos;s callback as
the error. The second argument to the callback will be an <code>object</code> with
either an <code>error</code> or a <code>value</code> property.</li>
</ul>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">function</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>async.parallel([
    async.reflect(function(callback) {
        // do some stuff ...
        callback(null, &apos;one&apos;);
    }),
    async.reflect(function(callback) {
        // do some more stuff but error ...
        callback(&apos;bad stuff happened&apos;);
    }),
    async.reflect(function(callback) {
        // do some more stuff ...
        callback(null, &apos;two&apos;);
    })
],
// optional callback
function(err, results) {
    // values
    // results[0].value = &apos;one&apos;
    // results[1].error = &apos;bad stuff happened&apos;
    // results[2].value = &apos;two&apos;
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="reflect.js.html">reflect.js</a>, <a href="reflect.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="reflectAll"><span class="type-signature">(static) </span>reflectAll<span class="signature">(tasks)</span><span class="type-signature"> &#x2192; {Array}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import reflectAll from &apos;async/reflectAll&apos;;
</code></pre>
<p>A helper function that wraps an array or an object of functions with <code>reflect</code>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>tasks</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>
|

<span class="param-type">Object</span>
|

<span class="param-type">Iterable</span>


            

            
            </td>

            

            <td class="description last"><p>The collection of
<a href="global.html">async functions</a> to wrap in <code>async.reflect</code>.</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>Returns an array of async functions, each wrapped in
<code>async.reflect</code></p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">Array</span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>let tasks = [
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;one&apos;);
        }, 200);
    },
    function(callback) {
        // do some more stuff but error ...
        callback(new Error(&apos;bad stuff happened&apos;));
    },
    function(callback) {
        setTimeout(function() {
            callback(null, &apos;two&apos;);
        }, 100);
    }
];

async.parallel(async.reflectAll(tasks),
// optional callback
function(err, results) {
    // values
    // results[0].value = &apos;one&apos;
    // results[1].error = Error(&apos;bad stuff happened&apos;)
    // results[2].value = &apos;two&apos;
});

// an example using an object instead of an array
let tasks = {
    one: function(callback) {
        setTimeout(function() {
            callback(null, &apos;one&apos;);
        }, 200);
    },
    two: function(callback) {
        callback(&apos;two&apos;);
    },
    three: function(callback) {
        setTimeout(function() {
            callback(null, &apos;three&apos;);
        }, 100);
    }
};

async.parallel(async.reflectAll(tasks),
// optional callback
function(err, results) {
    // values
    // results.one.value = &apos;one&apos;
    // results.two.error = &apos;two&apos;
    // results.three.value = &apos;three&apos;
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="reflectAll.js.html">reflectAll.js</a>, <a href="reflectAll.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#reflect">async.reflect</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="setImmediate"><span class="type-signature">(static) </span>setImmediate<span class="signature">(callback)</span><span class="type-signature"></span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import setImmediate from &apos;async/setImmediate&apos;;
</code></pre>
<p>Calls <code>callback</code> on a later loop around the event loop. In Node.js this just
calls <code>setImmediate</code>.  In the browser it will use <code>setImmediate</code> if
available, otherwise <code>setTimeout(callback, 0)</code>, which means other higher
priority events may precede the execution of <code>callback</code>.</p>
<p>This is used internally for browser-compatibility purposes.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>callback</code></td>
            

            <td class="type">
            
                
<span class="param-type">function</span>


            

            
            </td>

            

            <td class="description last"><p>The function to call on a later loop around
the event loop. Invoked with (args...).</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>args...</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
            </td>

            

            <td class="description last"><p>any number of additional arguments to pass to the
callback on the next tick.</p></td>
        </tr>

    
    </tbody>
</table>






    <h5>Example</h5>
    
    <pre class="prettyprint"><code>var call_order = [];
async.nextTick(function() {
    call_order.push(&apos;two&apos;);
    // call_order now equals [&apos;one&apos;,&apos;two&apos;]
});
call_order.push(&apos;one&apos;);

async.setImmediate(function (a, b, c) {
    // a, b, and c equal 1, 2, and 3
}, 1, 2, 3);</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="setImmediate.js.html">setImmediate.js</a>, <a href="setImmediate.js.html#line3">line 3</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#nextTick">async.nextTick</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
            

    

    <h4 class="name" id="timeout"><span class="type-signature">(static) </span>timeout<span class="signature">(asyncFn, milliseconds, info<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import timeout from &apos;async/timeout&apos;;
</code></pre>
<p>Sets a time limit on an asynchronous function. If the function does not call
its callback within the specified milliseconds, it will be called with a
timeout error. The code property for the error object will be <code>&apos;ETIMEDOUT&apos;</code>.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>asyncFn</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>The async function to limit in time.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>milliseconds</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            

            
            </td>

            

            <td class="description last"><p>The specified time limit.</p></td>
        </tr>

    

        <tr>
            
                <td class="name"><code>info</code></td>
            

            <td class="type">
            
                
<span class="param-type">*</span>


            

            
                <span class="optional">&lt;optional&gt;</span>
            
            </td>

            

            <td class="description last"><p>Any variable you want attached (<code>string</code>, <code>object</code>, etc)
to timeout Error for more information..</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>Returns a wrapped function that can be used with any
of the control flow functions.
Invoke this function with the same parameters as you would <code>asyncFunc</code>.</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    


    <h5>Example</h5>
    
    <pre class="prettyprint"><code>function myFunction(foo, callback) {
    doAsyncTask(foo, function(err, data) {
        // handle errors
        if (err) return callback(err);

        // do some stuff ...

        // return processed data
        return callback(null, data);
    });
}

var wrapped = async.timeout(myFunction, 1000);

// call `wrapped` as you would `myFunction`
wrapped({ bar: &apos;bar&apos; }, function(err, data) {
    // if `myFunction` takes &lt; 1000 ms to execute, `err`
    // and `data` will have their expected values

    // else `err` will be an Error with the code &apos;ETIMEDOUT&apos;
});</code></pre>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="timeout.js.html">timeout.js</a>, <a href="timeout.js.html#line4">line 4</a>
    </li></ul></dd>
    

    

    

    
</dl>












        
            

    

    <h4 class="name" id="unmemoize"><span class="type-signature">(static) </span>unmemoize<span class="signature">(fn)</span><span class="type-signature"> &#x2192; {<a href="global.html">AsyncFunction</a>}</span></h4>

    



<div class="description">
    <pre class="prettyprint source"><code>import unmemoize from &apos;async/unmemoize&apos;;
</code></pre>
<p>Undoes a <a href="#memoize">memoize</a>d function, reverting it to the original,
unmemoized form. Handy for testing.</p>
</div>











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>


        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>fn</code></td>
            

            <td class="type">
            
                
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


            

            
            </td>

            

            <td class="description last"><p>the memoized function</p></td>
        </tr>

    
    </tbody>
</table>




<h5>Returns:</h5>

        
<div class="param-desc">
    <p>a function that calls the original unmemoized function</p>
</div>



<dl class="param-type">
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="global.html">AsyncFunction</a></span>


    </dd>
</dl>

    






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="unmemoize.js.html">unmemoize.js</a>, <a href="unmemoize.js.html#line1">line 1</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><p><a href="#memoize">async.memoize</a></p></li>
        </ul>
    </dd>
    

    
</dl>












        
    

    

    
</article>

</section>




    <footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> using the Minami theme.
</footer></div>
</div>

<nav id="toc">
    <h3>Methods:</h3><ul class="nav methods"><li class="toc-header"><a href="#collections">Collections</a></li><li data-type="method" class="toc-method"><a href="#concat">concat</a></li><li data-type="method" class="toc-method"><a href="#concatLimit">concatLimit</a></li><li data-type="method" class="toc-method"><a href="#concatSeries">concatSeries</a></li><li data-type="method" class="toc-method"><a href="#detect">detect</a></li><li data-type="method" class="toc-method"><a href="#detectLimit">detectLimit</a></li><li data-type="method" class="toc-method"><a href="#detectSeries">detectSeries</a></li><li data-type="method" class="toc-method"><a href="#each">each</a></li><li data-type="method" class="toc-method"><a href="#eachLimit">eachLimit</a></li><li data-type="method" class="toc-method"><a href="#eachOf">eachOf</a></li><li data-type="method" class="toc-method"><a href="#eachOfLimit">eachOfLimit</a></li><li data-type="method" class="toc-method"><a href="#eachOfSeries">eachOfSeries</a></li><li data-type="method" class="toc-method"><a href="#eachSeries">eachSeries</a></li><li data-type="method" class="toc-method"><a href="#every">every</a></li><li data-type="method" class="toc-method"><a href="#everyLimit">everyLimit</a></li><li data-type="method" class="toc-method"><a href="#everySeries">everySeries</a></li><li data-type="method" class="toc-method"><a href="#filter">filter</a></li><li data-type="method" class="toc-method"><a href="#filterLimit">filterLimit</a></li><li data-type="method" class="toc-method"><a href="#filterSeries">filterSeries</a></li><li data-type="method" class="toc-method"><a href="#groupBy">groupBy</a></li><li data-type="method" class="toc-method"><a href="#groupByLimit">groupByLimit</a></li><li data-type="method" class="toc-method"><a href="#groupBySeries">groupBySeries</a></li><li data-type="method" class="toc-method"><a href="#map">map</a></li><li data-type="method" class="toc-method"><a href="#mapLimit">mapLimit</a></li><li data-type="method" class="toc-method"><a href="#mapSeries">mapSeries</a></li><li data-type="method" class="toc-method"><a href="#mapValues">mapValues</a></li><li data-type="method" class="toc-method"><a href="#mapValuesLimit">mapValuesLimit</a></li><li data-type="method" class="toc-method"><a href="#mapValuesSeries">mapValuesSeries</a></li><li data-type="method" class="toc-method"><a href="#reduce">reduce</a></li><li data-type="method" class="toc-method"><a href="#reduceRight">reduceRight</a></li><li data-type="method" class="toc-method"><a href="#reject">reject</a></li><li data-type="method" class="toc-method"><a href="#rejectLimit">rejectLimit</a></li><li data-type="method" class="toc-method"><a href="#rejectSeries">rejectSeries</a></li><li data-type="method" class="toc-method"><a href="#some">some</a></li><li data-type="method" class="toc-method"><a href="#someLimit">someLimit</a></li><li data-type="method" class="toc-method"><a href="#someSeries">someSeries</a></li><li data-type="method" class="toc-method"><a href="#sortBy">sortBy</a></li><li data-type="method" class="toc-method"><a href="#transform">transform</a></li><li class="toc-header"><a href="#controlflow">Control Flow</a></li><li data-type="method" class="toc-method"><a href="#applyEach">applyEach</a></li><li data-type="method" class="toc-method"><a href="#applyEachSeries">applyEachSeries</a></li><li data-type="method" class="toc-method"><a href="#auto">auto</a></li><li data-type="method" class="toc-method"><a href="#autoInject">autoInject</a></li><li data-type="method" class="toc-method"><a href="#cargo">cargo</a></li><li data-type="method" class="toc-method"><a href="#cargoQueue">cargoQueue</a></li><li data-type="method" class="toc-method"><a href="#compose">compose</a></li><li data-type="method" class="toc-method"><a href="#doUntil">doUntil</a></li><li data-type="method" class="toc-method"><a href="#doWhilst">doWhilst</a></li><li data-type="method" class="toc-method"><a href="#forever">forever</a></li><li data-type="method" class="toc-method"><a href="#parallel">parallel</a></li><li data-type="method" class="toc-method"><a href="#parallelLimit">parallelLimit</a></li><li data-type="method" class="toc-method"><a href="#priorityQueue">priorityQueue</a></li><li data-type="method" class="toc-method"><a href="#queue">queue</a></li><li data-type="method" class="toc-method"><a href="#race">race</a></li><li data-type="method" class="toc-method"><a href="#retry">retry</a></li><li data-type="method" class="toc-method"><a href="#retryable">retryable</a></li><li data-type="method" class="toc-method"><a href="#seq">seq</a></li><li data-type="method" class="toc-method"><a href="#series">series</a></li><li data-type="method" class="toc-method"><a href="#times">times</a></li><li data-type="method" class="toc-method"><a href="#timesLimit">timesLimit</a></li><li data-type="method" class="toc-method"><a href="#timesSeries">timesSeries</a></li><li data-type="method" class="toc-method"><a href="#tryEach">tryEach</a></li><li data-type="method" class="toc-method"><a href="#until">until</a></li><li data-type="method" class="toc-method"><a href="#waterfall">waterfall</a></li><li data-type="method" class="toc-method"><a href="#whilst">whilst</a></li><li class="toc-header"><a href="#utils">Utils</a></li><li data-type="method" class="toc-method"><a href="#apply">apply</a></li><li data-type="method" class="toc-method"><a href="#asyncify">asyncify</a></li><li data-type="method" class="toc-method"><a href="#constant">constant</a></li><li data-type="method" class="toc-method"><a href="#dir">dir</a></li><li data-type="method" class="toc-method"><a href="#ensureAsync">ensureAsync</a></li><li data-type="method" class="toc-method"><a href="#log">log</a></li><li data-type="method" class="toc-method"><a href="#memoize">memoize</a></li><li data-type="method" class="toc-method"><a href="#nextTick">nextTick</a></li><li data-type="method" class="toc-method"><a href="#reflect">reflect</a></li><li data-type="method" class="toc-method"><a href="#reflectAll">reflectAll</a></li><li data-type="method" class="toc-method"><a href="#setImmediate">setImmediate</a></li><li data-type="method" class="toc-method"><a href="#timeout">timeout</a></li><li data-type="method" class="toc-method"><a href="#unmemoize">unmemoize</a></li></ul><h3>Methods:</h3>
</nav>

<br class="clear">




<script src="https://cdn.jsdelivr.net/prettify/0.1/prettify.js"></script>

<script src="https://cdn.jsdelivr.net/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/typeahead.js/0.11.1/typeahead.bundle.min.js"></script>
<script>prettyPrint();</script>
<script src="scripts/async.js"></script>

<script src="scripts/linenumber.js" async></script>
<script src="scripts/jsdoc-custom.js" async></script>
</body>